The scope variables updated by the directive are not reflected where we have {{variable}}
on the page, however they do show up as being updated in when I do console.log(scope)
.
<script>
var demoApp = angular.module('demoApp', []);
demoApp.controller('demoController', function demoController($scope) {
$scope.myElementId ="abcd";
$scope.updateVals = function() {
$scope.myElementClass = "";
};
});
demoApp.directive('demoSelect', function() {
return {
restrict: 'A',
controller: 'demoController',
link: function(scope, element, attrs, controller) {
element.on("click", function(event) {
event.stopImmediatePropagation();
event.preventDefault();
scope.ele = angular.element(event.target);
angular.element(".selected").removeClass("selected");
$(scope.ele).addClass("selected");
var mm = $(scope.ele).get(0);
scope.myElementId = $(scope.ele).attr("id");
scope.myElementClass = $(scope.ele).attr("class");
scope.myElementType = mm.tagName;
});
}
};
});
</script>
Here is the plunker for it. What am I missing?