AngularJS ngModelController

南笙酒味 提交于 2019-12-07 03:53:25

Have you tried this:

console.log(JSON.stringify(ctrl));
if(ctrl.$valid == true) {
    console.log(JSON.stringify(ctrl));
}

or

console.log("$valid is ", ctrl.$valid);
if(ctrl.$valid == true) {
    console.log("$valid should be true and is actually ", ctrl.$valid);
}

It could be related to this (old) Chrome bug. I believe the expected behavior is that when you expand the object in the console you get the value of the object at expansion time, not at log time, so you would need to print the object as a string or clone it when logging.

Edit - Some more details...

If you run this var obj = {a: 1, b: {}}; console.log(obj); obj['a'] = 2; console.log(obj); in the Chrome console you will see this being output:

> Object {a: 1, b: Object}
  a: 2
  b: Object
  __proto__: Object

> Object {a: 2, b: Object}
  a: 2
  b: Object
  __proto__: Object

Edit 2

Hopefully this will answer your question. It appears that you may be adding a parser to the $parsers array after $setViewValue(...) has been called. As a result, when your directive is first initialized any validations you have added will not have been executed. You can manually execute them by calling something like ctrl.$setViewValue(ctrl.$viewValue); after your parser has been added.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!