簡體   English   中英

父控制器的角度切換指令

[英]Angular toggle directive from parent controller

當父控制器中的某些元素發生事件時,如何顯示/隱藏指令?

 app.directive('rest', function(){ return { restrict: 'E', scope: false, replace: true, link: function(scope, elem, attr) { }, templateUrl: '<div ng-show="showDirective"></div>', } }); 
 <div ng-controller="AppCtrl"> <rest></rest> <div ng-click="showDirective = false"><div> <!-- hide directive --> <div ng-click="showDirective = true"><div> <!-- show directive --> </div> 

在這里,您的錯誤是“ templateUrl”而不是“ template”。 當您提供html內聯用戶“模板”時,當您在單獨的html文件中提供html時,請使用“ templateUrl”並提供html模板的網址:

http://plnkr.co/edit/xzqOvcjKYfWxazWfHWyS?p=preview

  .directive('rest', function(){
    return {
      restrict: 'E',
      scope: false,
      replace: true,


  link: function(scope, elem, attr) {

  },   
  template: '<div ng-if = "showDirective" >Test</div>',
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM