我有一个简单的代码:
define(['app'],function(app)
{
app.factory('factoryProvider',function(){
return {
name: 'my Name'
}
});
app.directive('myDiv',['factoryProvider',function(factoryProvider) {
return {
restrict: 'E',replace: true,templateUrl: 'link/to/template.html',controller: function($scope) {
},link: function(scope,routeParams,location) {
console.log(factoryProvider.name);
}
};
}])
});
我想要能够在链接功能中访问myFactory,但是我不能!我也尝试过link:function(scope,routeParams,location,factoryProvider),也没有工作。为什么?
它应该已经在链接功能内部可用了
app.factory('factoryProvider',function(){
return {
name: 'my Name'
}
});
app.directive('myDiv',function(factoryProvider) {
return {
restrict: 'E',template: '<p>{{name}}</p>',controller: function($scope) {
},link: function(scope) {
scope.name=factoryProvider.name;
}
};
}]);