Directives and scope

Descrição

A-Level Angular Notas sobre Directives and scope, criado por James Drummond em 03-05-2015.
James Drummond
Notas por James Drummond, atualizado more than 1 year ago
James Drummond
Criado por James Drummond aproximadamente 9 anos atrás
10
1

Resumo de Recurso

Página 1

An Angular directive inherits its parent's scope by default.Modify the scope of the directive using the property 'scope' in the directive object.scope : false- This is the default. The directive does not create a new scope, it just uses the parent one.- There is no inheritance but this is not generally a good way of creating re-usable componentsscope : true- Directive has a new scope which prototypically inherits from the parent scope- If more than one directive (under the same parent) requests a new scope, only one scope will be created. (As you would expect: all models should be in sync across duplicate directives)- Be wary of two way data-binding to primitives in the parent scope (do not inherit from primitives in the parent scope as data binding will not work).

scope : {}- Creates new scope, nothing inherited from parentInheriting distinct items from parent$scope.car = {type : 'hyundai', doors : 3}// Cannot insert html due to idiocy from GoConqryou need to create an attribute on the element: carProperty=car // Note no quotes around car. car can be an object.scope : {localProperty : '=car-property'} // Two directional binding with car objectattribute on element : car-name="{{car.name}}" scope : { carName : '@carName' } // Only inherits a string!! Not two way binding!attribute on element:sayhelloFunction='sayHelloThere()'; // sayHello() is function in the parent scopescope : { sayHello : '&sayHelloFunction'} // Now if you call sayHello in the directive, sayHelloThere will be called in the parent

Semelhante

Directives, compile and link
James Drummond
Angular
Kingsley Bawuah
The Princeton Review Chapter 9 Rotational Motion
Anibal Santamaria
JavaScript Fundamentals
Andrew Watters
Direct Effect - European Union
Tatiana Nikolaid
Scope and Inheritance in Angular
James Drummond
Angular Nuts and Bolts
James Drummond
Direct Effect - EU Public Law
Tatiana Nikolaid
Angular application scaffolding
James Drummond
Direct Effect and Union Acts
cadhla_corrigan
FE Web Applications Components
Juan Carlos Joya Carvajal