简体   繁体   English

如何在角度js中将自定义指令包含到另一个自定义指令的模板(html)中

[英]How to include custom directive to another custom directive's template(html) in angular js

I hava a directive already(appView) and that has some html to load through templateUrl. 我已经有一个指令(appView),它具有一些可以通过templateUrl加载的html。 As of now, I need to add one more custom directive to the template that is being used by another directive(appView). 到目前为止,我需要向另一个指令(appView)所使用的模板中添加一个自定义指令。

Please see my code below and it is not working as expected. 请在下面查看我的代码,它无法正常工作。 Any help on this how i can make this work please? 请问对此有什么帮助吗?

View.html (template) View.html(模板)

<div>
    <div class="dragdrop" id="dropzone" dropzone> //here is my custom directive
        <div class="fileUpload btn btn-primary">
        <span>UPLOAD ASSETS</span>
        <input id="dzFile" type="file" class="upload" />
        </div> 
    </div>
</div>

angular js 角js

var appModule = angular.module("Newapp", []);

appModule.directive("appView", appView);
function appView(){
    var directive = {
        restrict: 'E',
        templateUrl: 'app/View.html'
    };
    return directive;
}

appModule.directive("dropzone", function(){  //This is added to the View.html as attribute(see above html code with **)
    var directive = {
        restrict: 'A',
        link: FullDragDrop
    };
    return directive;
});

function FullDragDrop(){
    console.log("soemthing goes here");
}

How can I make this possible Please? 我怎样才能做到这一点?

This code works for me. 该代码对我有用。 Make sure templateUrl: 'app/View.html' exists 确保templateUrl:'app / View.html'存在

<script>

var appModule = angular.module("Newapp", []);

    appModule.directive("appView", appView);

        function appView(){

            var directive = {
                restrict: 'E',
                templateUrl: 'view.html'
            };

            return directive;

      }



    appModule.directive("dropzone", function(){  //This is added to the View.html as attribute(see above html code with **)


         var directive = {
                restrict: 'A',
                link: FullDragDrop
            };

            return directive;

    });




    function FullDragDrop(){

        console.log("soemthing goes here");

    }


</script>

<script type="text/ng-template" id="view.html">
   <div class="dragdrop" id="dropzone" dropzone> //here is my custom directive
          <div class="fileUpload btn btn-primary">
          <span>UPLOAD ASSETS</span>
          <input id="dzFile" type="file" class="upload" />
          </div> 
      </div>
</script>

<body>
  <app-view></app-view>
</body>

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

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