gpt4 book ai didi

javascript - 如何将变量从 html 传递到指令 AngularJS?

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

我有一个 html,我需要显示一个弹出窗口。我有这个:

<div class="dashboardTr" ng-repeat="post in posts">
<modal-dashboard header="Success" body="post.ID" id="success"></modal-dashboard>
</div>

以及该指令:

app.directive('modalDashboard', function() {
return {
restrict: 'E',
scope: {
header: '@header',
body: '=',
id: '@id'
},
templateUrl: '/modalDashboard.html'
}
});

弹出窗口的新 HTML 为:

<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">{{ header }}</h4>
</div>
<div class="modal-body">
<p>{{ body }}</p>
</div>
</div>

这不起作用。如果我将字符串传递到 body 属性中,它就会起作用。有什么问题?它位于另一个指令内。这会是问题所在吗?谢谢!

最佳答案

这应该有效:

app.directive('modalDashboard', function() {
return {
restrict: 'E',
scope: {
header: '@header',
body: '=body', // <-- make sure to modify this to evaluate body attribute
id: '@id'
},
templateUrl: '/modalDashboard.html'
}
});

关于javascript - 如何将变量从 html 传递到指令 AngularJS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37316648/

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