如何查找自定义指令中的所有输入元素&基于某些条件设置只读

时间:2017-07-20 11:53:57

标签: javascript angularjs dom angular-directive jqlite

(function() {
  "use strict";

  angular
    .module("app")
    .directive("myCustomDirective", myCustomDirective);

  myCustomDirective.$inject = ["$compile"];

  function myCustomDirective($compile) {
    return {
      restrict: "E",
      templateUrl: "app/views/template.html",
      scope: {
        ui: '=info',
        index: '=',
      },
      compile: function(tElem, tAttrs) {
        // console.log(': compile => ' + tElem.html());
        return {
          pre: function(scope, iElem, iAttrs) {},
          post: function(scope, iElem, iAttrs) {
            //console.log(scope);
            //console.log(iElem[0].innerHTML);
          }
        }
      }

      //controller: 'd3PhaseController'
    };
  }
}());

指令模板

<div class="col-md-6">
   <textarea class="form-control" ng-required="true"></textarea>
</div>

控制器

vm = {
    "SomeId" : "This id will fetched from the server"
};
  

我正在寻找的是vm.SomeId == 1然后找到所有输入   自定义指令中的元素&amp;让它只读

是的,我知道我可以很容易地把

<textarea class="form-control"  ng-attr-readonly="{{some check}}"></textarea>

但这是一种开销,因为我有这样的控制器&amp;这样的指令。

0 个答案:

没有答案
相关问题