Alerts ignore ng-hide/ng-show
If you use ng-show on an alert directive it will not work because it appears to always be overwritten with the closable status.
See this plurk - http://plnkr.co/edit/ZvCs3fcpWUrvJPXEyYHT for a example.
@nicstrong It is not about the closable property but a scoping issue. Basically the alert directive creates a new isolated scope. In AngularJS one DOM element can have only one scope attached to it so the ng-hide gets "locked" in an isolated scope. You can easily work-around it by doing the following:
<alert ng-hide="$parent.hideAlerts" type="error">Alert with directive</alert>
But I agree that this is not very intuitive. The idea behind the alert directive was that is was mostly data-driven... but people seem to be bumping into this scoping issue over and over again, so we might drop an isolated scope from this directive.
@angular-ui/bootstrap I know, it was discussed before... What is your take on this one?
Thanks for the explanation. It is clear now the issue.
Is there a reason for creating the isolated scope?
@nicstrong yes, usually when a directive provides a template it should have an isolated scope. We had a longish discussion about it in https://github.com/angular-ui/bootstrap/issues/285
Also Misko's video on directives writing (http://www.youtube.com/watch?v=WqmeI5fZcho) has an excellent discussion on it toward the end of the video. I've got an impression that this part is often not well understood
Having said the above I really can see that this might be confusing, especially for alerts... Not sure what the best curse of actions... On one hand I understand that in some practical cases the current solution is not good. At the same time if feels "right". Dunno, I guess practicality should win :-)
I'd say a child scope would be better in this case... if what's "right" is making it hard and confusing for most people, then it may not be "right" :rabbit:
Yeh, it should be practice that determines what is "right" :-) Let's turn this directive into one that uses a child scope then!
@nicstrong So, I had a look at this issue, crafted a PR and then we had a lengthy discussion about it (see https://github.com/angular-ui/bootstrap/pull/398). Finally we are coming to the conclusion that isolated scopes are "good thing".
If you want to refer to variables in a parent scope just prefix them with $parent, as I've proposed above.
Ok, i am happy with that :+1: with that. At the time I was 1 week into using javascript/angular for the first time. So the whole scoping thing was very confusing to a C++/C#/Java programmer. But I am finally starting to get the hang of things.
+1, please add this somewhere in the documentation.
+1 on the >> docs comment.
+1 "Yeh, it should be practice that determines what is "right" :-)"