Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

TypeError: parsedNgModelAssign is not a function #11913

Closed
AndrewIsh opened this issue May 20, 2015 · 10 comments
Closed

TypeError: parsedNgModelAssign is not a function #11913

AndrewIsh opened this issue May 20, 2015 · 10 comments

Comments

@AndrewIsh
Copy link

Plunker

When trying to make use of ng-model-options and getterSetter: true, I am receiving the following error when trying to set:

TypeError: parsedNgModelAssign is not a function
    at NgModelController.$$setOptions.ngModelSet (angular.js:20414)
    at NgModelController.$$writeModelToScope (angular.js:20863)
    at writeToModelIfNeeded (angular.js:20857)
    at angular.js:20851
    at validationDone (angular.js:20779)
    at processAsyncValidators (angular.js:20762)
    at NgModelController.$$runValidators (angular.js:20707)
    at NgModelController.$$parseAndValidate (angular.js:20844)
    at NgModelController.$commitViewValue (angular.js:20812)
    at NgModelController.$$debounceViewValueCommit (angular.js:20942)

I am unable to find a declaration for parsedNgModelAssign().

In my template:

<label ng-model="cont.getSetRole(role.role)" ng-model-options="{ getterSetter: true }" btn-checkbox class="btn"></label>

In my controller:

myCont.getSetRole = function(roleId) {
   return true;
}

Toggling the btn-checkbox triggers the error.

@AndrewIsh
Copy link
Author

OK, this may not be an issue at all. Adding { updateOn: 'change' } to the ng-model-options seems to fix it.

@Narretz
Copy link
Contributor

Narretz commented May 25, 2015

Interesting. Can you post a plnkr with a reproduction?

@ryanhart2
Copy link
Contributor

Looking at your Plunk, I think that ng-model="getSet()" should be ng-model="getSet" as per the example on the Angular website https://docs.angularjs.org/api/ng/directive/ngModelOptions.

I don't think that { updateOn: 'change' } is a valid setting. Is 'change' an event that can occur on a label? By adding this, the setter is not being called at all (only the getter), which is why there is no error. If you change to { updateOn: 'default' } which is valid, then the setter is called and the error returns.

Unless you disagree, I think that Angular is working correctly and this issue can be closed.

@Narretz
Copy link
Contributor

Narretz commented May 26, 2015

@ryanhart2 is right, the model must not be a fn expression if it is a getterSetter. Likewise, ngModel on a label should not really work; it doesn't have an input method, it does not fire events, and it's not possible to set its value.

@AndrewIsh
Copy link
Author

Yep, thanks @ryanhart2 and @Narretz, my mistake, sorry! :) Please close.

@jforjava1981
Copy link

jforjava1981 commented May 31, 2016

@AndrewIsh @Narretz @ryanhart2 I received a similar error when I used function expressions. And in the examples on https://docs.angularjs.org/api/ng/directive/ngModelOptions. it clearly uses function expressions.
`

Name:
user.name = 
`

is it because it is used with ng-bind and not ng-model? Must we use function expression with ng-bind ? If function expression must not be used then I believe example in doc should indicate so. Can I raise a issue here for suggestions on docs?

@gkalpak
Copy link
Member

gkalpak commented May 31, 2016

@jforjava1981, it's not clear how you are using it and if it is supported.

Only ngModel "understands" ngModelOptions. If you are using it in any other way, it is not supported. If you are using it with ngModel and still think there is an issue with Angular itself, please open a new issue.

If you think the docs can be improved, a pull request is most welcome 😃 (but opening an issue about it helps as well).

@jforjava1981
Copy link

jforjava1981 commented May 31, 2016

@gkalpak Got it !! I missed that ng-model in the example is indeed using it correctly without function expressions. . So as ng-bind doesn't even consider ng-model-options while using ng-bind we have to refer a property as it should (function expression if its a function or normal property reference otherwise) Hope now I understand it correctly.

@nehagupta13688
Copy link

Hello Guys, I am upgrading my angular project from 1.5.8 to 1.6.4 and after updating the project, when I run the application I am getting following exceptions on the console. Not sure why it is happening.

angular.js:14525 TypeError: modelCtrl.$$initGetterSetters is not a function
at Object.ngModelPreLink (angular.js:29213)
at angular.js:1346
at invokeLinkFn (angular.js:10426)
at nodeLinkFn (angular.js:9792)
at compositeLinkFn (angular.js:9055)
at compositeLinkFn (angular.js:9058)
at compositeLinkFn (angular.js:9058)
at publicLinkFn (angular.js:8920)
at Object.link (angular.js:27844)
at angular.js:1346 ""

TypeError: ctrl.$isEmpty is not a function
at Array. (angular.js:24772)
at ngModelWatch (angular.js:28954)
at Scope.$digest (angular.js:17991)
at Scope.$apply (angular.js:18269)
at done (angular.js:12387)
at completeRequest (angular.js:12613)
at XMLHttpRequest.requestLoaded (angular.js:12541)
at XMLHttpRequest.nrWrapper (localhost/:15)

@gkalpak
Copy link
Member

gkalpak commented Apr 26, 2017

@nehagupta13688, the migration guide is a good place to start.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants