I have an element that I am displaying on the web page - this element is a twitter bootstrap icon -
``.
When the page loads, the icon is hidden by applying the hidden class to it with the style:
.hidden {
display: none;
}
Now, I have created a directive which in its simplest form looks like:
var app = angular.module('testApp', []);
app.directive('testDir', function() {
return function(scope, iElement, iAttrs) {
iElement.customMethod({
source: function() {
//Some other statements
jQuery(".icon-trash").removeClass('hidden');
}
});
};
});
This directive is placed on an input box as an attribute. When the user enters an input text, the directive function is indeed called. However, the icon is never displayed again, that is the jQuery code does not seem to remove the hidden class even though the function is called (checked using `console.log()`). Any idea why? I think you should read stackoverflow.com/questions/14994391/… and consider using ng-class instead of writing a complex directive ?
以上就是AngularJS + jQuery - Unable to hide / show element inside directive的详细内容,更多请关注web前端其它相关文章!