Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度错误:多个指令要求新的/隔离的范围_Angularjs_Angularjs Directive_Angularjs Scope - Fatal编程技术网

Angularjs 角度错误:多个指令要求新的/隔离的范围

Angularjs 角度错误:多个指令要求新的/隔离的范围,angularjs,angularjs-directive,angularjs-scope,Angularjs,Angularjs Directive,Angularjs Scope,我有两个指示: app.directive('autofocus', function ($timeout) { return { scope: { trigger: '=autofocus' }, replace: false, link: function (scope, element) { scope.$watch('trigger', function (value) { if (value

我有两个指示:

app.directive('autofocus', function ($timeout) {
  return {
    scope: {
      trigger: '=autofocus'
    },
    replace: false,
    link: function (scope, element) {
      scope.$watch('trigger',
        function (value) {
          if (value) {
            $timeout(function () {
              element[0].focus();
            });
          }
        }
      );
    }
  };
});

app.directive('checkCustomerName', function(Customer) {
  return {
    require: 'ngModel',
    scope: {
      value: '=ngModel'
    },
    link: function(scope, elm, attrs, model) {
      var CUSTOMERNAME_REGEXP = /^([ \u00c0-\u01ffa-zA-Z'\-])+$/;
      var retval;
      model.$parsers.unshift(function(viewValue) {
        if (CUSTOMERNAME_REGEXP.test(viewValue)) {
          var current = attrs.customerId;
          var exists = Customer.findByName(viewValue);
          if (exists && exists !== current) { // customer name exists already
            model.$setValidity('taken', false);
            model.$setValidity('invalid', true);
          } else { // customer name does not exist
            model.$setValidity('taken', true);
            model.$setValidity('invalid', true);
            retval = viewValue;
          }
        } else { // customer name is not valid
          model.$setValidity('taken', true);
          model.$setValidity('invalid', false);
        }
        return retval;
      });
      elm.bind('blur', function() {
        if (model.$viewValue) { // capitalize all words in value
          model.$viewValue = capitalizeAllWords(model.$viewValue);
          model.$render();
        }
      });
    }
  };
});
单独使用时,它们的工作效率很低,但在同一元素上使用时,我得到:

Multiple directives [autofocus, checkCustomerName] asking for new/isolated scope on:
<input type="text" autofocus="true" check-customer-name>
多个指令[autofocus,checkCustomerName]要求在以下位置设置新的/隔离的作用域:
我怎样才能让他们一起工作?

(很抱歉,我没有深入研究ng指令逻辑,但是…:-()。

只需删除其中一个指令的隔离范围,并查看该属性即可

F.e


我有相同的错误“多个指令要求新的/隔离的作用域”。 在我的例子中,问题是有多个相同名称的指令注册

.directive('directiveName', () => {})
.directive('directiveName', () => {});
在不正确的合并后发生。
删除其中一个解决了此问题。

我遇到了相同的问题,并尝试了此解决方案,但它总是给我值=未定义。您能告诉我缺少什么吗?
.directive('directiveName', () => {})
.directive('directiveName', () => {});