I'm learning directives from Thinkster, when I actually load the index.html, and hover over "Say Something", in the console i get:
["howdy", "hi", "hello"]---
I'm expecting ["hello", "howdy", "hi"]--- assuming the directives get evaluated from left to right, so first hello gets pushed into $scope.words, then howdy, then hi, but that clearly is not what happens here, what does actually go on beneath the hood?
Angular Code:
(function() {
'use strict';
angular.module('greetings', [])
.directive("welcome", function() {
return {
restrict: "E",
controller: function($scope) {
$scope.words = [];
this.sayHello = function() {
$scope.words.push("hello");
};
this.sayHowdy = function() {
$scope.words.push("howdy");
};
this.sayHi = function() {
$scope.words.push("hi");
};
},
link: function(scope, element){
element.bind("mouseenter", function() {
console.log(scope.words);
});
}
}
})
.directive("hello", function() {
return {
require: "welcome",
link: function (scope, element, attrs, welcomeCtrl) {
welcomeCtrl.sayHello();
}
};
})
.directive("howdy", function() {
return {
require: "welcome",
link: function (scope, element, attrs, welcomeCtrl) {
welcomeCtrl.sayHowdy();
}
};
})
.directive("hi", function() {
return {
require: "welcome",
link: function (scope, element, attrs, welcomeCtrl) {
welcomeCtrl.sayHi();
}
};
});
})();
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Egghead Directive</title>
<link rel="stylesheet" href="styles.css">
</head>
<body ng-app="greetings">
<welcome hello howdy hi>Say something!</welcome>
<!-- Javascripts -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
<script src="main.js"></script>
</body>
</html>