ngModel and component with isolated scope

Posted by Artem Andreev on Stack Overflow See other posts from Stack Overflow or by Artem Andreev
Published on 2012-08-10T06:46:40Z Indexed on 2012/09/11 3:38 UTC
Read the original article Hit count: 279

Filed under:

I am creating simple ui-datetime directive. It splits javascript Date object into _date, _hours and _minutes parts. _date uses jquery ui datepicker, _hours and _minutes - number inputs.

See example: http://jsfiddle.net/andreev_artem/nWsZp/3/

On github: https://github.com/andreev-artem/angular_experiments/tree/master/ui-datetime

As far as I understand - best practice when you create a new component is to use isolated scope.

When I tried to use isolated scope - nothing works. ngModel.$viewValue === undefined.

When I tried to use new scope (my example, not so good variant imho) - ngModel uses value on newly created scope.

Of course I can create directive with isolated scope and work with ngModel value through "=expression" (example). But I think that working with ngModelController is a better practice.

My questions:

  1. Can I use ngModelController with isolated scope?
  2. If it is not possible which solution is better for creating such component?

© Stack Overflow or respective owner

Related posts about angularjs