如何将作用域传递给 AngularStrap $Alert?

How to pass scope to AngularStrap $Alert?

我是 angular 的新手,我正在使用 angularstrap 制作自定义警报,并使用 ng-repeat

在对象上重复数据

这是我的 angular 代码

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()">&times;</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-表带版本 v2.1.6 - 2015-01-11

根据 docs,您可以将 controllercontrollerAs 选项传递给警报模式。

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>
...

scope 添加到您的提醒电话中。

js

let alertExcpetion = $alert({
    placement: 'top-right',
    type: 'warning',
    show: true,
    keyboard: true
    template: 'alert.template.html',
    scope:$scope
});