Angular.js v1.3.0-rc.0 directive ngModelController $viewValue always string
With latest angular 1.3-rc release, encounter a problem with directives.
- passing ng-model to directive with object values
- adding to directive ng-model and require ng-model
- getting ngModelController.$viewValue as string ["Object object", "Object object"]
Yes, this was changed recently. How do you normally handle your object models? The standard way is to have a formatter that formats your object as a string. Can you give an example (plunkr) of your use case? To clarify, as the $viewValue should represent what the user sees, it makes sense that it is always a string.
The other formatters come after the default one (toString), so you cannot format the object anymore.
Ah, I see have. Have you tried unshifting your formatter in the $formatters? Then it should run before the string formatter.
@pdanpdan: If you use a directive with a higher than default priority and use $formatters.push(yourFormatter) in the post-link function, it should be applied first.
@Narretz: Since $formatters are applied in the reverse order, you need to push() it (so it gets applied first) and you should also make sure that your push() happens after the input directive's push()
Thank you for the solution. I just checked and it solves the problem of displaying the value, but the field does not validate (if it is required.
@pdanpdan Please post a minimal reproducible example in a plunker etc.
No, that sounds like a separate issue --- please file a different bug about that with a reproduction, thanks.
I don't think we want to consider this a regression, because we can't support viewValues which are not strings --- it would break core validators. @matsko / @shahata feel free to reopen if you think I"m wrong here
Yes that's true, anything that comes from input type: empty, text, url or email must be handled as a string value since element.value always expects them to be a string.