【问题标题】:Can not access variable on Popover template from Angularjs Component无法从 Angularjs 组件访问 Popover 模板上的变量
【发布时间】:2017-01-12 13:01:15
【问题描述】:

我正在使用 AngularJs 1.5 版。我创建了一个简单的组件来添加评论

angular.module('myapp')
.component('comments', {
    templateUrl: "views/component/comments.html",
    bindings: { },
    controller: function ($http, $rootScope, $interval, $scope) {
        var ctrl = this
        ctrl.users = $rootScope.users;
        console.log(ctrl.users); // This variable had value
    }
})

然后,在视图中,我放置一个按钮来显示一个弹出框

<button popover-is-open="$ctrl.userListPopoverStatus" popover-title="Add User" uib-popover-template="'views/popover/order_select_user.html'" popover-placement="top" class="btn btn-primary" ng-model="$ctrl.users"><i class="fa fa-fw fa-tags"></i></button>

我的弹出框模板

<div class="row margintop-10">
<form class="form-horizontal">
    <table class="table table-striped small_table_user">
        <tr>
            <td>
                <input type="text" class="form-control" ng-model="$ctrl.searchText" placeholder="Search user" />
            </td>
        </tr>
        <tr ng-repeat="user in $ctrl.users | filter:$ctrl.searchText">
            <td ng-click="pickUserProcess(user.id)">{{user.name}}</td>
        </tr>
    </table>
</form>
</div>

但看起来,Bootstrap Popover 无法访问 $ctrl.users 变量,因此列表用户根本不显示。我该如何解决这个问题?

【问题讨论】:

    标签: javascript angularjs angular-ui-bootstrap popover


    【解决方案1】:

    我猜这是角点问题的原因。 试试:

    var ctrl = {}
    ctrl.users = $rootScope.users;
    

    【讨论】:

      猜你喜欢
      • 2017-11-04
      • 2013-06-19
      • 2016-11-27
      • 2017-01-30
      • 1970-01-01
      • 2012-05-04
      • 2017-08-29
      • 1970-01-01
      • 2014-07-20
      相关资源
      最近更新 更多