javascript - Difference between ways to declare a scope in a directive (ways shown inside) -


i'm new angularjs, javascript , html.

my question is: ¿what difference between 4 ways declare scope in directive?

i'm going show way , write think it. if i'm wrong or right, tell me in ordered way please.

this base in directive:

var app = angular.module('myapp', []); app.directive('mydirective', function() {   return {     scope: //here go 4 ways   } }); 

first way:

scope: true 

what understand that:

a - new child scope created , child scope inherits parent scope surround it.

b - directive have access parent scope models.

c - possible insert values in scope. or scope meant give access inherited data?

second way

scope: { // no content, empty object } 

a - creates isolated scope.

b - scope can't access parent models.

c - although scope can't access parent scope, isolated scope can have child scopes.

third way

//nothing, not declaring scope attribute. 

fourth way

scope: {// content such data binding strategies} 

thanks. please let place share information related general question (so answers question), go further based on personal experience.

so summarized different types of creating scopes. forgot performance , why creating no isolating scopes can better.

isolating scope will:

  • reduce amount of variables in different scopes.
  • inheriting parent scope cause clone watchers, too.
  • prevent using multiple directives on 1 element.

with isolated scopes can't this:

<div mydirective mydirective2></div> 

this lead angular exception.


if not isolating scope:

  • maybe tons of inherited variables (can avoided scope: false)
  • can use multiple directives @ same element

for example ngmodel,ngclick,ngblur ... doesn't isolate scope, because can use them on same element. this:

<input ng-model="somevalue" ng-blur="storeinput()"></input> 

this wouldn't possible if they'd isolate scope.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -