toddmotto / angularjs-styleguide

AngularJS styleguide for teams
https://ultimateangular.com
5.96k stars 700 forks source link

ngModel on ES6 #108

Closed sibelius closed 8 years ago

sibelius commented 8 years ago

Is ngModel pattern deprecated on ES6?

How can I migrate from a ng-model directive to a component?

toddmotto commented 8 years ago

ng-model is just fine, not sure what you mean migrate it to a component?

sibelius commented 8 years ago

I've followed this tutorial - https://www.nadeau.tv/using-ngmodelcontroller-with-custom-directives/

If I want to implement a directive that provides a ng-model I need to implement NgModelController

like $formatters, $parsers, render, and so on

I'd like to know how can I achieve something similar using one-way data binding

toddmotto commented 8 years ago

Oh you mean require: '^ngModel' as the controller for the component. Yeah you can use that as it just requires the controller. You will need to implement your own $parsers and $formatters for model -> view and then view -> model, I actually cover this in my course, code sample here: https://github.com/toddmotto/ultimate-angular-master-src/blob/master/parsers-formatters/content/js/directives/couponFormat.js

However, what you'll likely need is $setViewValue and $render: https://github.com/toddmotto/ultimate-angular-master-src/blob/master/setviewvalue-render/content/js/directives/HTMLEditor.js#L4-L15

sibelius commented 8 years ago

so do you think ng-model is a good practice or should we removed it to use One-Way DataFlow and Events - https://github.com/toddmotto/angular-styleguide#one-way-dataflow-and-events?

toddmotto commented 8 years ago

How would you implement that with ng-model?