ng-conf 2014

Creando componentes propios para AngularJS con ngModelController

Jason Aden  · 

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

so my name is Jason Hayden I work for Salesforce on a project called desk calm and having a lot of fun at the conference here I've been doing angular for about a little bit over a year and a half now and one of the things that really impressed me was ng-model

controller and the ngmodel directive and how you can use it to build nice custom components so real quick why ngmodel its core to really good UI components it's it's the thing responsible for two-way data-binding and angular so when people ask you

you know what's what's the magic of angular and you know you show them the demo and you have the input you input the text and it shows on screen immediately that's ngmodel controller handling that it's heavily utilized porting jQuery components

so you know if you look at some of the packages in like angular UI and when you're reporting components like like the Select two component or date pickers you have two wired into the ng model controller it also allows you to create nice declarative components

so the input directive and angular has you know a couple of properties that you can apply to it min length max length ng pattern and when you write a piece of HTML like this you know a designer can take a look at it know what it is just about anybody could

take a look at it and know what it's doing and that's largely due to ng model controller and what it provides so how do you access it we may have covered this a little bit in some of the directive talks but you apply it you add ng model to your directive

you're going to require it and it'll come in in the link function as in this case the fourth argument ctrl you can also get access to it through element data the element data method and hit dollar ng model controller so what does it do so when you're

coming from the view and taking data from the view and putting it into the model it's going to interact with ng form this is for things like dirty and pristine and valid invalid it's going to transform your input into the model representation so real

simple like an input directive you type in text your model representation is text with a directive like say a radio button or a date picker your input might be something like a user click so you need to translate that user click into something in the model

so and your model controller handles that it also sends out alerts to listeners ng change would be an example it will alert ng change that your view value has changed when going from the model to the view it watches for changes in the model and it transforms

the model representation into a view representation so in the case of say a date object in your model you're going to want to format it properly for display so ng model controller handles that what doesn't it do it doesn't by itself listen for

[ ... ]

Nota: se han omitido las otras 1.291 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.