An example of this article describes the interaction between the ANGULARJS command and the controller. Share to everyone for your reference, specific as follows:
In this section, we look at the interaction between the controller and the instruction
1. First of all, the simplest way to call the parent controller in an instruction:
<div ng-controller= "MyController1" >
</div>
App.controller (' MyController1 ', [' $scope ', function ($scope) {
$scope. Load=function () {
console.log (' Loading data ......');
}
}]);
App.directive (' MyTest ', function () {
return{
restrict: ' E ',
link:function (scope,ele,attr) {
Ele.bind (' MouseEnter ', function () {
scope.load ();}}}}
)
In the first section, we already know how to invoke the method in the parent controller in the scope parameter of the instruction, here:
Can also be written as:
Scope. $apply (' Load () ');
2. The same instruction, in the dynamic invocation of multiple parent class controller methods:
<div ng-controller= "MyController1" loadmore= "Load1 ()" </div>
<div ng-controller= "MyController2" Loadmore= "Load2 ()" ></div>
App.controller (' MyController1 ', [' $scope ', function ($scope) {
$scope. Load1=function () {
Console.log (' Loading data ... '}
}]);
App.controller (' MyController2 ', [' $scope ', function ($scope) {
$scope. Load2=function () {
Console.log (' Loading data ... ";
}
}]);;
App.directive (' MyTest ', function () {
return{
restrict: ' E ',
link:function (scope,ele,attr) {
Ele.bind (' MouseEnter ', function () {
scope. $apply (Attr.loadmore ())}}}}
)
Note here:
Scope. $apply (Attr.loadmore ());
Loadmore is lowercase, and in HTML, attributes are obtained through the rules of the hump.
More readers interested in ANGULARJS related content can view the site topics: "Angularjs Introduction and Advanced Tutorials" and "ANGULARJS MVC Framework Summary"
I hope this article will help you to Angularjs program design.