You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your controllers have manifestation but not the services
<bodyng-app="myApp" ng-controller="mainController"><!-- here you go the scope has the existence since the controller has manifestation --></body>
varmyApp=angular.module("myApp",[]);varmainController=myApp.controller("mainController",function($scope,myService){//scope has a purpose and that is to link the object model to the html there in the viewmyService.getFromServer($scope.id).then(function(){//handle the object that is thrown by resolve case},function(){//handle the case that is thrown by reject case});})varmyService=myApp.service("myService",function($http,$q){this.getFromServer=function(id){vardeferred=$q.defer();$http.get(url).then(function(){//success of the server API call// HTTP 200 OK deferred.resolve({});},function(){//failure of the server API calldeferred.reject({ErrorMessage:"your error message from the server"})})returndeferred.promise}})
Services have no manifestation they are just to contain some logic that is agnostic of the view / html but reusable across the controllers
Controllers can have $scope and that has attributes which in turn are manifested
While making API calls it is an Aysnc operation and so it would involve promises
Promises are simple and have resolution and rejection