OK, I have this function in service:
wikiServices = angular.module ('Wiki Services', []); wikiServices.factory ( 'newsService', function ($ http, $ q) {var chosenNewsStory = ""; var getNewsStory = function (News_id, callback) {var off = $ q.defer (); $ http ({method: " GET ", url:" news / articles / "+ news_id}) .success (function (newsStory) {deferred.resolve (newsStory); console.log (" resolution "+ newsStory);}); deferred.promise return; });
Controller 1:
wikiControllers = angular.module ('wikiControllers', []); WikiControllerskcontroller ( 'Ctrll', [ '$ scope', 'newsService', function ($ scope, newsService) {$ scope.getNewsStory = newsService.getNewsStory (function (input) {newsService.getNewsStory (news_id);};} );
controller 2:
wikiControllers = angular.module ( 'wikiControllers', []); wikiControllers.controller (' ctrl1 ', [' $ scope ',' newsService ', $ scope.watch (' newsService.chosenNewsStory ', function (newVal) {console.log (newVal);});});
now, I have tried to set the "selected news story" in the service and I feel that I am not getting an important part of the whole JS experience.
Thank you. "Var selectedNewsStory"
Get the and set
methods to be defined, which are being shared, and also return them. Like the service:
wikiServices Factory ('newsService', function ($ http, $ q) {var selectedNewsStory = ""; Return {getNewsStory: function (news_id, callback) {var deferred = $ q.defer (); . $ Http ({method: "GET", url: "news / articles /" + news_id}) Success (function (newsStory) {deferred.resolve (newsStory); console.log ( "resolution" + newsStory);}) ; Refund refund. }, GetNews: function () {Selected Newsletter; }, SetNews: function (story) {selectedNewsStory = story; }}});
You can now view newsService.getNews ()
and set it with newsService.setNews (news)
Comments
Post a Comment