如何将数据发送到UI Bootstrap Modal窗口$ scope?

时间:2016-07-08 09:34:14

标签: javascript angularjs twitter-bootstrap pug angular-ui-bootstrap

我尝试打开模态窗口,从那里的SQL查询中发送数据并更改表单的值,但它不起作用。我想我应该把它发送到模态范围,但我不知道该怎么做。

js file:

addUser() {
    return this.Server.getUsers()
        .then((res) => {
            this.users = res.users;
            this.$modal.open({
                templateUrl: 'user.html'
            });
        });

和玉文件:

script(type="text/ng-template", id="users.html")
    div.page-header: h1 !{__('Users')}
    div.panel.panel-default
        div.panel-heading
            h3.panel-title !{__('Users')}
        table.table.table-hover.table-condensed
            thead
                tr
                    th.col-lg-2 !{__('Name')}
                    th.col-lg-5 !{__('Description')}
            tbody
                tr(ng-repeat="u in users.users")
                    td {{u.name}}
                    td {{u.description}}

1 个答案:

答案 0 :(得分:0)

解决方案:

   addUser() {
        return this.$modal.open({
            templateUrl: 'user.html',
            controller: ['$scope', 'Server', function ($scope, Server) {

                $scope.users = Server.getUsers()
                    .then((res) => {
                        this.users = res.users;
                    });
            }],
            controllerAs: "add_user"
        }).result.then((res) => {
            return console.log("Saved");
        });
    }