简体   繁体   中英

Directive: ngModel not change ng-hide

I started build a directive calendar and I have a problem:

I'm putting dynamic tables and want to filter by a ngModel that is parent controller, but I can not take the change of ngModel using dynamic tables and attr.

Here is the code:

HTML

<li class="checkbox">
   <input type="checkbox" ng-model="confirm.is_true" checked class="checked-blue">
   <label>Confirm</label>
</li>

JS

function createBar(kind) {
    var _span = document.createElement("div");
    switch(kind){
      case "initial":
        var _img = document.createElement("img");
        var _text = document.createTextNode("Test");
        _img.src = "/uploads/photo/27/sq135_DSC_0011.JPG";
        _span.appendChild(_img);
        _span.appendChild(_text);
        _span.className = "bar-init";
        _span.setAttribute("ng-hide", "confirm.is_true");
        break;
      case "middle":
        _span.className = "bar-middle";
        break;
      case "end":
        _span.className = "bar-end";
        break;
    }
    return _span;
  }

Thanks

The problem is, I think that angular is not aware of the fact that you are creating this element. You should definitely have a look into $compile method. Instead of using document.createElement use angular.element . After creating desired element, use $compile(_span)($scope) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM