get path variable inside templateUrl

122 Views Asked by At

i have angularjs 1 project. i have used ng router.

i want to use url appName in templateUrl path, so how can i do this ?

enter image description here

after adding this i am geeting below error.

ReferenceError: appName is not defined
    at http://localhost:5000/app.js:12:27
    at Object.invoke (http://localhost:5000/library/angular.min.js:44:390)
    at d (http://localhost:5000/library/angular.min.js:42:279)
    at http://localhost:5000/library/angular.min.js:42:418
    at r (http://localhost:5000/library/angular.min.js:8:7)
    at g (http://localhost:5000/library/angular.min.js:42:180)
    at gb (http://localhost:5000/library/angular.min.js:46:250)
    at c (http://localhost:5000/library/angular.min.js:22:19)
    at Uc (http://localhost:5000/library/angular.min.js:22:332)
    at we (http://localhost:5000/library/angular.min.js:21:1
1

There are 1 best solutions below

2
Rakesh Burbure On

Please create a service like this, and inject this into your config.

app.factory('dataservice', function () {
    var appName;
    return {
        getApp: function(){
            return appName;
        },
        setApp: function (str) {
            appName = str;
        }
    }
});

Inject this like below

app.config(function(dataservice){
    var app = dataservice.getApp(); // to get the app name.
    dataservice.setApp('My App'); // to set the app name
})

Please let me know if you face any issues..