Das Verständnis, wie die Richtlinie Priorität der Arbeit in Angularjs

app.js ist:

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);
        }
    };
});

Und index.html ist:

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

Obwohl Priorität für my-directive2 ist kleiner als my-directive3 noch, warum my-directive2 wird immer ausgeführt? Sollte es nicht die Richtlinie mit höherer Priorität, die in diesem Fall ist my-directive3?

InformationsquelleAutor user4904589 | 2015-10-16

Schreibe einen Kommentar