AngularJS でコントローラーとサービスを作成するさまざまな例を見続けていますが、混乱しています。2 つのアプローチの違いを誰かに説明してもらえますか?
app.service('reverseService', function() {
this.reverse = function(name) {
return name.split("").reverse().join("");
};
});
app.factory('reverseService', function() {
return {
reverse : function(name) {
return name.split("").reverse().join("");
}
}
});
また、コントローラーの例:
function ExampleCtrl($scope) {
$scope.data = "some data";
}
app.controller("ExampleCtrl", function($scope) {
$scope.data = "some data";
}