我是角色新手,我正在使用angularstrap制作自定义提醒,并使用ng-repeat重复对象上的数据
这是我的角度代码
let alertExcpetion = $alert({
placement: 'top-right',
type: 'warning',
show: true,
keyboard: true
template: 'alert.template.html'
});
这里是alert.template.html
<div class="alert" ng-class="[type ? 'alert-' + type : null]">
<button type="button" class="close" ng-if="dismissable" ng-click="$hide()">×</button>
<div class="title">
{{ someScopeTitle }}
</div>
<div>
<table class="table table-alert">
<tbody>
<tr ng-repeat="student in students">
<td>{{ student.id }}</td>
<td><a href="#" ng-click="myfunction(student.someObject)">View File</a> {{student.fullname}}</td>
</tr>
</tbody>
</table>
</div>
</div>
加载后,.alert为空,因为它没有读取范围。有没有办法将范围传递给angularstrap的$ alert?
angular-strap版本v2.1.6 - 2015-01-11
答案 0 :(得分:2)
将 scope
添加到您的提醒通话中。
<强> JS 强>
let alertExcpetion = $alert({
placement: 'top-right',
type: 'warning',
show: true,
keyboard: true
template: 'alert.template.html',
scope:$scope
});
答案 1 :(得分:0)
根据docs,您可以将controller
和controllerAs
选项传递给提醒模式。
<强> another.controller.js 强>
let alertExcpetion = $alert({
placement: 'top-right',
type: 'warning',
show: true,
keyboard: true
template: 'alert.template.html',
controller: 'ModalController',
controllerAs: 'ctrl'
});
<强> modal.controller.js 强>
.controller('ModalController',...
$scope.someScopeTitle = 'title';
...
<强> alert.template.html 强>
...
<div class="title">
{{ ctrl.someScopeTitle }}
</div>
...