简体   繁体   English

如何在angular js中调用指令?

[英]How to call a directive in angular js?

.directive('clinicalTrailModal', function ($compile) {
  return {
    restrict: 'EA',
      scope: {
          context: '=',
          dui: '='
      },
    templateUrl: 'app/templates/lbdAdsModal.html'
   })

I am calling this directive based on true false condition like below, 我正在根据如下所示的真假条件调用此指令,

<clinical-trail-modal  value="currentUrl" dui="typeDisease._id" data-ng-if="clinicalTrailModal"></clinical-trail-modal>

But it does'nt work.When I remove 但这不起作用。当我删除时

 restrict: 'EA',
      scope: {
          context: '=',
          dui: '='
      },

this it works.I am new to angularjs.Can anyone please help me.Thanks. 这是可行的。我是angularjs的新手,任何人都可以帮助我。谢谢。

It's possibly failing due to you passing context into the scope. 由于您将上下文传递到范围,因此可能会失败。 Either remove context, pass it in, or make it optional. 删除上下文,将其传递或使其为可选。

 restrict: 'EA',
      scope: {
          context: '=?', //optional
          dui: '='
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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