gpt4 book ai didi

javascript - 如何避免渲染指令元素

转载 作者:行者123 更新时间:2023-11-28 17:56:03 25 4
gpt4 key购买 nike

是否可以隐藏我的指令 html 元素?我的意思是如果我有这个指令:

app.js

angular.module("myApp", [])
.directive("myDirective", function() {
return {
restrict: "E",
template: "<div><p>Some text...</p></div>"
}
);

仅渲染模板的内容。

<div>
<p>Some text...</p>
</div>

不是指令元素:

<my-directive>
<div>
<p>Some text...</p>
</div>
</my-directive>

最佳答案

是的,只需将 replace: true 放入指令中即可。它将删除该元素

angular.module("myApp", [])
.directive("myDirective", function() {
return {
restrict: "E",
template: "<div><p>Some text...</p></div>",
replace: true
}
);

演示

angular.module("app",[])
.controller("ctrl",function($scope){


}).directive("myDirective", function() {
return {
restrict: "E",
template: "<div><p>Some text...</p></div>",
replace : true
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<my-directive>
</my-directive>
</div>

关于javascript - 如何避免渲染指令元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44417354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com