我有angularjs 1项目。我用过ng路由器。
我想在templateUrl路径中使用url appName,那么我该怎么做?
添加此内容后,我发现错误如下。
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
答案 0 :(得分:0)
请创建这样的服务,并将其注入您的配置中。
app.factory('dataservice', function () {
var appName;
return {
getApp: function(){
return appName;
},
setApp: function (str) {
appName = str;
}
}
});
像下面这样注入
app.config(function(dataservice){
var app = dataservice.getApp(); // to get the app name.
dataservice.setApp('My App'); // to set the app name
})
如果遇到任何问题,请告诉我。.