angularjs - load jsonp into multiple anglarjs controllers -
I have a jsonp call on the server that gives two object-containing objects.
At this time I make jsonp calls with jQuery because I have still started learning angular and I do not know how this is done.
I What is the correct way to get it with angular? Hello Please see here data.filters in
navController and
data.results in
contentController
(function ($, angular) {$ (function () {$ .ajax ({jsonp: "JSONPCallback", url: 'myUrl', data type: 'jsonp', success: Function (data) {// data = {"Filters": {...}, "results": {...}}}}};}); var app = angular. Module ('app', [] ); Var Controller = {}; Controller .navcontroller = function ($ scope) {$ scope.filters = [{}};} Controller Content Controller = Function ($ scope) {$ scope.results = [{}};} ; App.controller (Controller);}) (JQuery, Angular);
var app = angular module ('plunker', []); app.service ('d Tatasva ', function ($ http) {var url = "http://public-api.wordpress.com/rest/v1/sites/wtmpeachtest.wordpress.com/posts?callback=JSON_CALLBACK" var DataReady = false var filter = []; Var result = []; function getData () {if (datarendi) otherwise {$ http.jsonp (url) .success (data) {// in your case // angular.kopi (data.filter, Filter) //angular.copy (data. Result, result) angular.copy (data. Post [0], results); Angular copying (data post [1], filter); Return to {{filter: filter, result: result, getData: getData}}) app.controller ('MainCtrl', 'error' Function ($ scope, data service) {$ scope.name = 'World'; $ scope.items = DataService.results; dataService.getData ();}); App.controller ('seconds' Ctrl, function ($ radius, data service) {$ scope.filters = dataService.filters; dataService.getData ();});
Comments
Post a Comment