angular.js - $rootscope对应的controller在哪里?可以用什么方法获取到?
给我你的怀抱
给我你的怀抱 2017-05-15 17:06:32
0
2
659

在网上看到很多都在讲,每个$scope都有对应controller,那么$rootscope的controller在哪里呢?是ng-app属性所在标签里的ng-controller,那么如果ng-app所在标签没有ng-controller,那么对应的controller又应该怎么表示?

给我你的怀抱
给我你的怀抱

reply all(2)
伊谢尔伦

First of all, let me answer with a sentence from a Shanghai mayor in reply to a Hong Kong reporter: "I haven't heard of it."
This statement is not clear enough. What exactly does this controller refer to? If it is the ngController instruction, this sentence is obviously putting the cart before the horse. It is the ngController directive that creates a new scope. If it refers to the controller function in the instruction, it is obviously wrong. Many instructions do not have a controller function at all.

So, you’d better post the URL that holds this view here. . .
In addition, ngApp corresponds to the root scope, which is $rootscope. I may be relatively new to it and don’t know its corresponding controller yet. I hope other experts can correct me

仅有的幸福

I think it is easier to understand it this way:
Controller - controller is just a kind of encapsulation... It is a definition of AngularJS design pattern, nothing more. There is no corresponding relationship.

We create a controller through the ng-controller directive.
We can also create a controller through the $controller service.
Controllers use more services through another design pattern of AngularJS - dependency injection. For example $scope. And you don’t have to inject $scope at all...but why do you have to use $scope? Because you can understand $scope as a high-speed channel between pages and data, or a bridge, or a connection, or an adhesive...that is, in the controller If you want everything defined to be reflected on the page, you must pass $scope
for example

controller:
$scope.text = "hello world!";

view: 
{{ text }}

Therefore, there is no corresponding relationship between controller and $scope scope. They have nothing to do with each other. It's like, you have two pieces of paper and you want to make a model, and you also need glue. Do you think there is a corresponding relationship between paper and glue?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template