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?
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
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?