I created a directive which uses parent scope.
The directive should accept a attribute i.e
<my-nice-new-directive data-hide-icon="true" />
but I do not want to isolate scope. Is it possible to just add the attribute to the $scope?
I created a directive which uses parent scope.
The directive should accept a attribute i.e
<my-nice-new-directive data-hide-icon="true" />
but I do not want to isolate scope. Is it possible to just add the attribute to the $scope?
Consider having fun with the $parse service.
.directive('myNiceNewDirective', function () {
return {
restrict: 'AE',
controller: function ($scope, $attrs, $parse) {
var hideIcon = $parse($attrs.hideIcon)($scope);
}
};
})
or you could just evaluate the variable data-hide-icon="{{isIconHidden}}", in which case you may want to watch it.
.directive('myNiceNewDirective', function () {
return {
restrict: 'AE',
scope: true, //this is not necessary but could be useful
controller: function ($scope, $attrs) {
$scope.$watch(function () {return $attrs.hideIcon;}, function (newValue, oldValue) {
//react to change...
});
}
};
})