【发布时间】:2014-09-15 15:53:09
【问题描述】:
我对提供商有一些疑问。 有人能解释一下为什么我不能从控制器访问“setText”提供程序功能吗? 我只能访问 $get 块内的函数。
var myMod = angular.module('myApp', []);
myMod.controller("mainCtrl", [ "$scope","greeting", function($scope, greeting){
greetingProvider.setText("Hi, ");
}]);
myMod.provider('greeting', function() {
var text = 'Hello, ';
this.setText = function(value) {
text = value;
};
this.$get = function() {
return function(name) {
console.log(text + name);
};
};
});
myMod.config(function(greetingProvider) {
greetingProvider.setText("Howdy there, ");
});
myMod.run(function(greeting) {
greeting('Ford Prefect');
});
谢谢
【问题讨论】: