search

Home  >  Q&A  >  body text

How angular.js receives data passed from the background

I encountered a problem in the TP project. The front-end page is a list implemented with angular.js. I first passed the background json array to the page:
//ag configuration information
var ag_data = {};
ag_data.address = '{$address}';
ag_data.url = "{:U('')}";
console.log(ag_data.url);
Then a js file is referenced at the bottom of the page, which contains a logic written in angular.js. I pass it in the page You can get the url in the js file, but you can't get it in the controller

The error printed by the browser is like this

How to pass external values ​​​​to the scope of angular. . .
I am a newbie, please give some guidance╮(╯▽╰)╭

淡淡烟草味淡淡烟草味2795 days ago696

reply all(3)I'll reply

  • 世界只因有你

    世界只因有你2017-05-15 17:15:34

    https://docs.angularjs.org/er...$injector/unpr?p0=$applyProvider%20%3C-%20$apply%20%3C-%20localCon
    I suspect that your localCon controller has Question

    You try changing the controller to this way

    angular.module('myApp', [])
    .controller('MyController', ['myService', function (myService) {
      // Do something with myService
    }]);

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-15 17:15:34

    The error message has already told you that the instance method in apply 那里有问题。因为 $apply$scope cannot be injected directly here. .

    You just write:

    app.controler('localCon', function ($scope, $timeout, $http) {});

    That should be enough. These three are all built-in services of AngularJS, so there is no problem in injecting them explicitly without brackets.

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-15 17:15:34

    Change $http.post to $http.get

    reply
    0
  • Cancelreply