The difference between assinging scope to be "true" and "{}" is that in the first case the directive's scope becomes an instance of the parent scope (the scope of the parent controller) and therefore can use its data. But when we write 'scope: {}', we get a fully isolated scope without direct access to the parent scope.
Hi Joe, Awesome Video. Just an FYI. There are three types of scopes in angular directives. 1. Shared Scope 2. Inherited Scope 3. Isolated Scope. Ex: scope:false (shared scope and its default) scope:true (inherited scope. parent scope is visible) scope:{} (isolated scope parent scope is not visible).
There is a difference when we set scope:true or scope:{} when set to true , it means that directive template can inherit scope from the parent directives or controllers. but not the siblings. when set to {}, it means that no outer scope is available in the directive template.
@11:40 you said {} works and true works also and you didn't know why {} works. I believe the reason why it works is because it is looking for a truthy statement and in JavaScript and empty object literal is a truthy value. ({} == true) is true or you can just test it with !!{} It is one of the weird things about JS.
+Michael Warner no brother there is a big difference in using {} or true. There is a difference when we set scope:true or scope:{} when set to true , it means that directive template can inherit scope from the parent directives or controllers. but not the siblings. when set to {}, it means that no outer scope is available in the directive template.
Good questions, Miguel! First, yes, I am injecting the module into APP, and the module could contain multiple directives and more (services, factories, etc.) As far as having a module for every directive, I would consider the complexity and potential for reuse in other projects before creating a new module. In my example I took something trivial and created a module to teach the concept and and show the method, but the example directive would not have warranted it in production.
Better separation is certainly a good goal, but there are a number of ways to achieve this without requiring jQuery. You could use the templateUrl option in the directive linking to an external HTML file, or a an inline template script with a type of "text/ng-template."
I get the loud keyboard thing a lot... I think I have situated things better in later videos to avoid it being so loud. Who knows... maybe it's my trademark now.
scope: true - this creates a new scope for the directive that prototypically inherits from the parent scope (so that you have access to parent scope data). Downside (or not) is that if you have several directives on an element (e.g. as attributes), there's only one scope created for them (inherited from the element's scope) scope: {} - it creates a new, "isolated" scope. it means it does not inherit from parent scope, so you don't worry about parent vars - useful for reusable components :)
Thank you for this good tutorial, I think for a good separation fo html and javascript code , we have to create the template inside html in a script tag and use it with jQuery .html() method in the template attribute of angular.js. Do you agree with me ?
Sorry a bit off-topic, but how did you setup sublime to get to create a HTML 5 blank template ? Do you have other handy tips like these ? perhaps make a video, also about bower and other bits would be useful ?
Very helpful. I find so many things posted are unhelpful and leave me frustrated and this does just the opposite. Please keep posting your thoughts/discoveries.
hey @Joe Maddalone, that plugins and all you installing by command prompt is there any othere way i mean downloading from website and put that in directory and work from there.. please guide me, I am rookie in angular
This is the second time one of your framework videos has helped me. Thanks for putting this together! I like how the example is lean enough to type into an editor, then tweak it until you understand how it works.
Hey Joe :) At the end of the video you are putting the directive into a module and you are inserting the js file into the index.html page. So I was wondering, if my application gets really big and I have let's say 10 different modules each having different directive(s), do I have to include every js with the directives manually in the index.html file? Do you know if there is another way to gather all this directives in one place and include all js files just once into index.html ? Thank you, Gabriela
Yes you can, there are multiple ways to do this. I always use templates and views, so I only place them in the index.html and do some routing (search for routing in angular for more info). You could also create an HTML file with all your scripts and do a ng-include. Ofcourse you would have to import angular itself. Otherwise it won't work.
Just discovered something that sounded a bit odd, the Link and Template don't work together now in context of this example. What is happening is that the template is rendered before the attributes are picked up from the link function. Another video tells me that transclude does the trick ? But i could not figure out how to pickup attributes in a template by setting transclude:true ? Any Tips ?
Had to recreate it from my own video, but still works just fine. plnkr.co/edit/Ar92D0etGj7f8QoajM3X I also have a video on transclude here: AngularJS Transclude
Joe Maddalone The difference is, it no longer works with custom element directives. I forked your example and changed the directive .. have a look. plnkr.co/edit/FuUJRTCXqC0EAbWs2KWC?p=preview