如何从angularjs中的模板html调用指令 [英] How to call directive from template html in angularjs
本文介绍了如何从angularjs中的模板html调用指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML
在这个 html 模板文件中,我必须调用一个指令.我的指令名称是帮助".但是如果我添加来调用该指令,它就不起作用.如何在 angularjs 中调用 html 模板中的指令?
解决方案
我不确定我是否完全理解这个问题.这里是一个 jsfiddle,用于演示如何在 ng-template 中使用自定义指令.
或者试试这个..
angular.module('demo', []).directive('帮助', function() {返回 {模板:'<div>帮助!{{info}}</div>',范围: {信息:'@信息'}};}).controller('MainCtrl', ['$log',功能($日志){this.hello = '这是 MainCtrl';this.template = 'profile-template.html';//构造$log.debug('DemoCtrl 已加载');}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><body ng-app="演示"><script type="text/ng-template" id="profile-template.html"><div>这是 profile-template.html</div><div help info="这是指令信息."></div><div ng-controller="MainCtrl as main"><h2>只是一个演示</h2><div>{{main.hello}},包含来自{{main.template}}的模板</div><小时><div ng-include src="main.template"></div>