Javascript Angular指令-NgModelCtrl解析器问题

Javascript Angular指令-NgModelCtrl解析器问题,javascript,angularjs,angularjs-directive,directive,Javascript,Angularjs,Angularjs Directive,Directive,我有一个根据字段值显示符号的指令。这将附加到一个字段,如下所示: <input type="text" placeholder="" class="text-input" ng-class="example_class" ng-model="exmaple-model" my-directive /> module.directive("myDirective", function () { return { require: "?ngModel",

我有一个根据字段值显示符号的指令。这将附加到一个字段,如下所示:

<input type="text" placeholder="" class="text-input" ng-class="example_class" ng-model="exmaple-model" my-directive />
module.directive("myDirective", function () {
    return {
        require: "?ngModel",

        link: function (scope, element, attrs, ngModelCtrl) {
            /*breakpoints show the line above and below are reached*/
            ngModelCtrl.$parsers.push(function (val) {
                /* call to function to show symbol, this line is never reached */
            }
function parse(value) {
  if (value) {
    return value.toLowerCase();
  }
}
ngModelController.$parsers.push(parse);
代码正在到达
ngModelCtrl
行,但不再到达。调试表明,虽然
ngModelCtrl
看起来构建正确(具有函数和值等),
$parsers
为空-长度为0,但应该存在的函数没有

查看Chrome inspector不会产生错误。
$parsers
是否为空,或者是否有进一步调试指令的方法?

请检查

您是否尝试过将逻辑直接放在“调用函数以显示符号”与调用函数的位置?

请退出


您是否尝试过将逻辑直接放在“调用函数以显示符号”与调用函数的位置?

您的解析器显示长度为0,请尝试从parse方法返回一些值,并按如下方式使用它:

<input type="text" placeholder="" class="text-input" ng-class="example_class" ng-model="exmaple-model" my-directive />
module.directive("myDirective", function () {
    return {
        require: "?ngModel",

        link: function (scope, element, attrs, ngModelCtrl) {
            /*breakpoints show the line above and below are reached*/
            ngModelCtrl.$parsers.push(function (val) {
                /* call to function to show symbol, this line is never reached */
            }
function parse(value) {
  if (value) {
    return value.toLowerCase();
  }
}
ngModelController.$parsers.push(parse);

您的解析器显示长度为0,请尝试从parse方法返回一些值,并按如下方式使用它:

<input type="text" placeholder="" class="text-input" ng-class="example_class" ng-model="exmaple-model" my-directive />
module.directive("myDirective", function () {
    return {
        require: "?ngModel",

        link: function (scope, element, attrs, ngModelCtrl) {
            /*breakpoints show the line above and below are reached*/
            ngModelCtrl.$parsers.push(function (val) {
                /* call to function to show symbol, this line is never reached */
            }
function parse(value) {
  if (value) {
    return value.toLowerCase();
  }
}
ngModelController.$parsers.push(parse);

为什么有两种链接方法?(或者只是复制不好?)我想ngModel不应该是可选的(没有?)为什么有两种链接方法?(或者只是复制不好?)我想ngModel不应该是可选的(没有?)