如何将参数传递给' A'限制指令

时间:2014-07-14 07:29:14

标签: angularjs

我想将参数传递给'(属性)受限制指令的范围:

我有以下' E'限制指令

.directive("twValidation", function () {
return{
  restrict: "E",
  replace: true,
  scope: {
    field: '='
  },
  templateUrl: "partials/components/directives/common/tw-validation.tpl.html"
}

})

我这样用:

<tw-validation field="myField"></tw-validation>

但最终我想要这个:

<div tw-validation="myField">...</div>

如何在属性限制指令内传递参数?

2 个答案:

答案 0 :(得分:1)

.directive("twValidation", function () {
return{
  restrict: "A",
  replace: true,
  scope: {
    twValidation: '='
  },
  templateUrl: "partials/components/directives/common/tw-validation.tpl.html"
}

答案 1 :(得分:0)

请尝试以下方法:

.directive("twValidation", function () {
return{
  restrict: "E",
  replace: true,
  scope: {
    field: '=field'
  },
  templateUrl: "partials/components/directives/common/tw-validation.tpl.html"
}



<tw-validation field="myField"></tw-validation>