まあ、私はAngular Servciesとファクトリに疑問を抱き、return型に基づいて説明したチュートリアルを紹介しました。サービスから返される関数型を角で呼び出す方法
angular.module("Training").service("Service", tryDis);
angular.module("Training").factory("Factory", tryDis);
function tryDis(){
console.log("trying..");
return "tried";
}
をして、私が持っている::
現在、私は次のようしている
angular.module("Training").controller("Ctrl1", function($scope,Service, Factory){
$scope.serviceData = Service;
$scope.factoryData = Factory;
});
チュートリアルでは、工場出荷時は「試してみました」の文字列を返しながらサービスは、全体の機能自体を返す言うように。これはとてもうまかった。
私の主張は、関数型が返されていて、それも引数を取らないので、まだ何らかの形で関数が正しく実行されるということです。だから私は何とかサービスから "試して"得ます。
は、JSのfunction.prototype.call()を参照して、私が動作するようには思えない
angular.module("Training").controller("Ctrl1", function($scope,Service, Factory){
$scope.serviceData = this.call(Service);//also call(Service)
$scope.factoryData = Factory;
});
これを試してみました。 上記の場合、 "試した"文字列を取得するにはどうすればいいですか?
注:サービスの作成中に「this」を使用することにはかなり慣れています。
angular.module("Training").service("Service", tryDis);
function tryDis(){
this.output=function(){
console.log("trying..");
return "tried";
};
}
、その後のようなあなたのコントローラに返された値を取得する:しかし、ここで私の質問は、そのJS
:http://stackoverflow.com/questions/14324451/angular-service-vs-angular-factory – charlietfl