ng-messages未在指令中显示

时间:2016-08-30 14:01:41

标签: angularjs

我尝试尽可能多地重复使用代码,因此我将ng-messages包装在指令中。但是,消息不会显示..

<form name="elementForm" novalidate>
<md-input-container>
  <label>Category</label>
  <input ng-required="true" ng-model="item.category" name="category" type="text">
<administration-input-validation control="category" formname="elementForm"></administration-input-validation>
</md-input-container>
</form>

指令:

    angular.module('app.analytics')
  .directive('administrationInputValidation', function () {
    return {
      template:
      '<div ng-messages>' +
        '<div ng-message="required">This is required</div>' +
      '</div>',
      restrict: 'E',
      replace: true,
      require: '^form',
      scope: {
        control: '=',
        formname: '='
      },
      link: function(scope, element, attrs) {

        var formStr = attrs.formname + "." + attrs.control;
        element.attr("ng-messages", formStr + "." + "$error");
      }
    };
  });

我也尝试过硬编码,但它还没有显示

<div ng-messages="elementForm.category.$error">

更新

绑定现在有效,但它没有显示消息

0 个答案:

没有答案