如何将范围传递给AngularStrap $ Alert?

时间:2016-11-24 02:33:27

标签: angularjs angular-strap

我是角色新手,我正在使用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()">&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-strap版本v2.1.6 - 2015-01-11

2 个答案:

答案 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,您可以将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>
...