Detailed explanation of $ scope directly outside the Controller of Angularjs

I used to write a script for automatic message using WebQQ. Since WebQQ also directly uses technologies similar to jQuery operation DOM, the script can be implemented.

Nowadays, many web applications start to use AngularJS, MVVM causing the unable to operate DOM to change data directly. So facing the web version of WeChat, to implement an automatic script, you can’t use the DOM’s idea.

To modify data in AngularJS, first get Scope. In fact, how is the method of acquiring Scope is simple.

Since most Angular projects need to use jQuery as a supplement. You can get the domain inherited in the current selector content through the .scope () method in jQuery.


$ (‘DIV [Ng-Controller = “ListController”). Scope ();
   Example: Complete example. 

GET Angular’s Scope in jQuery
      Angular.Module ('app', []) .controller ('listcontroller', ['$ scope', function ($ scope) {$ scope.list = [1, 2, 3, 4, 5]; $ scope.test = function () {console.log ('test');}}]   $ (', "). (' Div [ng-controller =" listcontroller "]). Scope (); // Get Controller's Scope Controllerscope.test (); // log 'Test' Console.log (ControllerScope.list); // Log [1,2,3,4,5] $ ('Button'). Click (Function (E) {var scope = $ (e.target) .scope (); console.log (scope.item) // log item number scope.test (); // log 'Test'}})      Select {ip}}      
  • So open the web version of WeChat page (2016-06-05) Select people you need to send messages. Then execute the following script:
VAR controllerScope = $ ('div [ng-controller = "chatsenderController"]). Scope (); // Get ChatsenderController $ scopeControllerScope .ediTareActn ="Star Brother, Good afternoon"; // Set the message you need to send. That is, set the value of a $ scope a property. / / Trigger the "Send button" click event. $ (". Action a"). Trigger ("click");
Very good "plug-in mode".
The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Cloud.
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment