【发布时间】:2013-03-14 06:39:20
【问题描述】:
我有这种情况:
<somebutton></somebutton>
...
app.directive("somebutton", function(){
return {
restrict: "E",
scope: {
// not sure what i can do here
},
template: '<button ng-click="loadTemplate()" type="button">Text</button>',
link: function(scope, element){
scope.loadTemplate = function(){
//TODO: append "home.html" template inside body directive
}
}
}
});
...
<script type="text/ng-template" id="home.html">
<div>home</div>
</script>
...
<div body ></div>
这样做的其他方法可能是将按钮放在 html 中而不是模板中
<button ng-click="loadTemplate()" type="button">Text</button>
然后可能有一个控制器,它具有加载模板的 loadTemplate() 方法
但我不确定如何做到这一点。
令人困惑?是的:)
对这个问题有什么想法吗?
谢谢
【问题讨论】:
-
我最近开始使用 Angular 并确保正确地做事让我感到困惑......考虑像 Angular HTML 被视为模板,因此不确定使用其他带有 Angular 的模板工具......期待一些答案...
标签: javascript html templates button angularjs