Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS指令在AngularJS中不起作用_Javascript_Angular_Directive_Ng Upgrade - Fatal编程技术网

Javascript AngularJS指令在AngularJS中不起作用

Javascript AngularJS指令在AngularJS中不起作用,javascript,angular,directive,ng-upgrade,Javascript,Angular,Directive,Ng Upgrade,我有一个简单的Angular 7组件,用于规范化页面标记 page-title.component.ts page-title.component.html 该指令非常简单,但当我在Angularmy page titlecomponent中使用它时: <my-page-title> <div is-granted="role">Whatever</div> </my-page-title> <div class="panel pa

我有一个简单的Angular 7组件,用于规范化页面标记

page-title.component.ts

page-title.component.html

该指令非常简单,但当我在Angular
my page title
component中使用它时:

<my-page-title>
    <div is-granted="role">Whatever</div>
</my-page-title>
<div class="panel panel-default">
  <div class="panel-heading" *ngIf="title">
    <h3 class="panel-title">{{ title }}</h3>
  </div>
  <div class="panel-body">
    <ng-content></ng-content>
  </div>
</div>
(function () {
  function IsGrantedDirective(AuthManager) {
    return {
      restrict: 'A',
      link(scope, elem, attr) {
        if (AuthManager.isGranted(attr.isGranted)) {
          return;
        }
        console.log("I'm called");
        elem.remove();
      },
    };
  }

  angular
    .module('my.common')
    .directive('isGranted', IsGrantedDirective);
}());
<my-page-title>
    <div is-granted="role">Whatever</div>
</my-page-title>
 <my-page-title>
     <div> // <----
         <div is-granted="role">Whatever</div>
     </div>
 </my-page-title>