简体   繁体   English

使用angular-ui在模态窗口中生成表

[英]Generating table in modal window with angular-ui

I have web angular.js web application with some buttons there. 我有带有一些按钮的web angular.js Web应用程序。 And i need to open modal window if user will press on any button. 而且我需要打开模式窗口,如果用户将按下任何按钮。 Also there is table in modal window with set of cols which depends on which button user press. 在模态窗口中也有带有cols组的表,这取决于用户按下哪个按钮。 I'm trying to generate table with ng-repeat but i see empty table with no one cols every time. 我正在尝试使用ng-repeat生成表,但是每次都没有人说空表。

My table: 我的桌子:

<table class="table">
  <th class="th" ng-repeat="col in association_cols">
    <span>{{ col.name }}</span>
  </th>
</table>

And my controller: 而我的控制器:

open_modal = function() {
    $http(......, function(data){
       $scope.association_cols = [{'name' : data.result.one}, {'name', data.result.two}]
    }
}

But every time i'm seeing empty table with no one th 但每次我看到空的表格,没有一个th

I'm openning modal window with: 我用以下方式打开模式窗口:

$modalInstance = $modal.open({'templateUrl' : "views/Window.tpl.html"});

Thank you. 谢谢。

The scope that the modal will get is not the usual scope inheritance you are used to know. 模态将获得的作用域不是您习惯了解的常见作用域继承。 Everything the modal needs should be passed via the resolve property. 模态需求的所有内容都应通过resolve属性传递。 Also you should use a ModalController. 另外,您应该使用ModalController。

var myItem = {name: 'yeah'};

$modal.open({
   templateUrl : "views/Window.tpl.html",
   controller: MyModalController,
   resolve: {
     item: function() {return myItem},
   }
}).then(function(result) {
   //dialog was closed
});

MyModalController = function($scope, item) {
   $scope.item = item;
   console.log('MyModalController constructed and item was injected', item);
}

Update/Addition: With the rewritten angular-ui modal ( in versions prior to 0.6 this was the $dialogProvider) you now need to type the close/dismiss callback functions like this: 更新/添加:使用重写的angular-ui模式( 在0.6之前的版本中,这是$ dialogProvider),您现在需要键入如下的close / dismiss回调函数:

$modal.open({

}).result.then(function(result) {});

Your $http call's callback doesn't contain the returned data from which you populate the $scope.association_cols . $http呼叫的回调不包含您填充$scope.association_cols所返回的data It should be: 它应该是:

 $http(..., function(data) {...});

Did you define the modal's controller in the passed options to $modal.open() ? 您是否在传递给$modal.open()选项中定义了模态的控制器? Add a controller property after the templateUrl templateUrl之后添加controller属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM