3
app.js
是:如何理解指令優先級工作Angularjs
var app = angular.module('myApp',[]);
app.directive('myDirective2', function() {
return{
restrict: 'A',
priority: 100,
//template:"<h1>myDirective2</h1>",
controller: function ($scope, $element, $transclude,$timeout) {
//$scope.name = "executed myDirective2";
$timeout(function() {
$scope.name = "executed myDirective2";
}, 3000);
}
};
});
app.directive('myDirective3', function() {
return{
restrict: 'A',
priority: 200,
//template:"<h1>myDirective3</h1>",
controller: function ($scope, $element, $transclude, $timeout) {
$timeout(function() {
$scope.name = "executed myDirective3";
}, 3000);
}
};
});
而且index.html
是:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="js/angular.js" type="text/javascript"></script>
<script src="js/app.js" type="text/javascript"></script>
</head>
<body>
<div my-directive3 my-directive2></div>
<br/>
Name:{{name}}
</body>
</html>
儘管爲什麼找執行my-directive2
優先my-directive2
較小比my-directive3
仍?在這種情況下,它不應該是具有更高優先級的指令,是my-directive3
?