Richard Burkhardt Richard Burkhardt - 2 years ago 110
AngularJS Question

ngModel doen't pass data back to parent scope in directive

Related Post, but didn't help:
Scoping issue when setting ngModel from a directive

EDIT: ngModel and component with isolated scope didn't work either.

I got the some problem but in a more complex way i guess. I want to write a pulldown that does not use any input for data saving. I'd rather have the ngModel to take care of it.

The jsFiddel example above shows a demo where the above discriped methods didn't work.

// this is what should work but doesn't

For some reason the scope of the ngModelController is a sibling of my scope. so it doesn't pass the changes back to the parent. at least all other sibling scopes behave as you'd expext. i.e. ng-change works in combination.

Answer Source

Angularjs doesn't deal very well with direct bindings to primitive types.

If you change this line:

$scope.productId = 16;

to something like this:

$scope.selectedProduct = {
    id: 16

and change those references on the rest of the code, you should be able to overcome the issue.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download