javascript - AngularJS ng-route how to make http request on resolve -


I have a simple template with input and an anchor link, which will load another template by pressing it. I want to bring this second template information through http request.

I am using redirect ng-root on the template of the results by search template and by path / search / title by default: I have the resolution to request the results before loading the template () I am trying to use ()

The problem I am experiencing is that when I add a resolution, the controller initially stops (I think it will load after that Promise came back Land). This means that variables like search URLs are not started and the $ root parameters are empty when I print them on the controller search function.

How should I do this?

I am also not sure about the correct syntax for resolution. Is the first search a field variable?

  Resolution: {search: searchController.search}   

For the lazy people checking on the planker, here's the relevant code:

Routing

  .config (['$ routeProvider', function ($ route provider) {$ routeProvider. When ('/ search', {templateUrl: 'templates / search.html'} ). ('/ Search /: title', {templateUrl: 'templates / result.html', administrator: 'searchController', resolution: {search: searchController.search}}) Otherwise ({redirectTo: '/ search'} );}]);   

searchController

  var searchController = search.controller ('SearchControler', ["$ http", "$ scope", "$ location", ' $ RootScope ',' $ routeParams ', function ($ http, $ scope, $ location, $ rootScope, $ routeParams) {console.log ("Admin Constructor"); this.searchURL =' http: //www.myapifilms Com / Imdb? Title =% thetitle% & amp; format = JSON '; $ scope.response =' feedback here & gt; '; this.title =' '; this.defer = null; console.log (" PARAMS: "+ JSON.stringify ($ routeParams));}]); SearchController.search = Function Search Moffee ($ q, $ route param) {searchController.defer = $ q.defer; Var searchString = $ routeParams.title; Url = searchController.searchURL.replace ('% thetitle%', searchString); Console.log ("URL:" + url); SearchController.searchRequest (url); }; SearchController.searchRequest = function (url) {$ http.get (url) .success (function) {.... searchController.defer.resolve (); return searchController.defer.promise;}) .error (function ( Data, status, header, configuration) {... searchController.defer.resolve (); return search search.controller.defer.promise;})};    

I think that with you service Make and edit accordingly:

  Angular Modules ('myApp', ['Eonic', 'NGRUT', 'Starter', 'V. Directive']) .ron (function ($ ionicPlatform) {$ ionicPlatform.ready (function () {// Assistant by default Hide the bar (remove it to show the assistant bar above the keyboard for form inputs) if (window and .cordova.plugin.keyboard) {cordova.plugin keyboard: hdiexororibre ();} if (window statsbar) {StatsBarrest.default ();}})}) .Feature ("Search", Ph ($ Q, $ http) {returnMessage: function () {// return $ q.when ("response"); var promise = $ http ({method: 'GET', url: 'your_url'}). (Function (data, position, header, config) {return data;}};););) ();) (); ('(Search', 'template', 'search.html'}), ('' '$ routeProvider', function ($ route provider), {$ routeProvider} / search / title: '{templateUrl:' Result (Search) {search: search} (search) {return.getMessage ();}}}) Otherwise ({redirectTo: '/' / 'search.conf' Search'}); }]);   

Your planker has been forked:

I hope that whatever you wanted was found, to help others after returning your planer. to be done.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -