私はAngularで新しく、私はAngularで構築している私のウェブサイトに構造を持ってきています。Angularのサービス
私は複数のページで使用するいくつかの機能を持っているコントローラを持っています。私はこれらの機能からより良いサービスを作ることができると聞いています。どのように私はこれを行うことができますか?
これは現在の状態のコントローラです: $ scope.city関数と$ scope.specials関数からサービスを作成するにはどうすればよいですか?
app.controller('DataCtrl', function($scope,$http){
$scope.city = function(){
$scope.items = [];
$http.get('/getdata').then(function(d){
$scope.items = d.data;
$scope.selectedItem = $scope.items[0];
},function(err){
console.log(err);
});
};
/* Function for specialization data */
$scope.specials = function(){
$scope.special = [];
$http.get('/specialdata').then(function(d){
$scope.special = d.data[0];
},function(err){
console.log(err);
});
};
});
[Angular Dependency Injection](https://angular.io/docs/ts/latest/guide/dependency-injection.html)をご覧ください。 – Oliver