0

The problem is: Using ui-router 0.2.0 and angular 1.1.x, ng-model is not accepting changes to an input text field (I also tried checkbox and select dropdown with same dis-allowed change!).

However, an input text in an ng-repeat does work.

When the view/state loads initially, the values are populated from the model, but after that the problem manifests itself.

How can I fix the runnable example below to allow changes to the "Serial" input text field using ng-model?

See this plunker and image below: (Stetch the plunker preview window to account for poor css) http://plnkr.co/edit/bS8ZQuiJNG2uE4zuzvyB?p=preview

Problem example image: https://docs.google.com/drawings/d/1CQb1SmJqWsWnuG87T0jrhiOTJdXIh3XCqXEINdbvx5c/edit?usp=sharing

1

1 Answer 1

1

The problem is using ng-model with a promise. The solution is to resolve the promise, making the assignment to the $scope.myModel in the then(...) of the promise:

var promise = somethingAsyncThatReturnsAPromise();
var itemDeferred = $q.defer();
itemDeferred.promise.then(function(obj) {
  $scope.myModel = obj;
});
itemDeferred.resolve(promise);

This question is similar to: Using ng-model on a resolved promise in AngularJS (strange behavior)

Here is a fixed, simplified version (angular 1.2.3 + ui-router 0.2.0): http://plnkr.co/edit/eSQjfBpv1V6Q1WTiDV3N?p=preview

And the fixed original version (angular 1.1.5 + ui-router 0.2.0): http://plnkr.co/edit/W7nkH8p6HreKcPOnfEq1?p=preview

If there is a more elegant solution, I am interested.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.