Angularjs - 从模态引导窗口

时间:2016-03-29 15:22:38

标签: angularjs

我有下一个html表单(默认情况下禁用输入字段,名为unitCreator):

<div class="form-group col-xs-12 col-md-12">
    <label for="unitcreator" class="control-label unit-creator">Org. Unit Creator</label>
    <input type="text" class="form-control unit-creator" id="unit-creator" name="unit-creator" ng-model="unitCreator" ng-disabled="!unitCreator" />
    <a data-toggle="modal" data-target="#myModal"><img src="/WebOpportunities/static/img/ico_search.png" class="search" /></a>
</div>

图标打开一个窗口模式,带有一个html表,当我点击一行时,我希望输入字段unitCreator启用,以传递列值。

这是模态引导程序中的表格代码html:

<div class="modal-body">
<table class="table table-hover">
    <thead>
        <tr>
            <th>Branch</th>
            <th>Name</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="organizational in organizationals" ng-class="{'selected':$index == selectedRow}" ng-click="setClickedRow($index)">
      <td>{{organizational.branch}}</td>
            <td>{{organizational.name}}</td>
        </tr>
    </tbody>
</table>
</div>

这是我的代码js:

$scope.managers = [
 {name: 'Ana Faedo Iglesias'},
 {name: 'Cristina Menendez'},
 {name: 'Daniel Piriz'}
];

$scope.selectedRow = null;

$scope.setClickedRow = function(index){
    $scope.selectedRow = index;
}
$scope.createSelectRowClick = function(){
  if ($scope.selectedRow==null)
  {
    alert("Any rows selected");
  }
  else
  {
    //here, i enabled the unitCreator field input and i put the column value of the table inside input field unitCreator


    $scope.unitCreator = false; //this not working

    //alert("hola" + $scope.selectedRow);
    //alert("valuetd " + $scope.organizationals[$scope.selectedRow].name)
  }
}

我以此示例为基础选择表格行:http://code.ciphertrick.com/2014/12/06/highlight-a-selected-row-in-ng-repeat-using-ng-class/演示:http://code.ciphertrick.com/demo/ngClass/

列值,我得到它(但我不知道如何通过它,到unitCreator输入字段的模态窗口):

$scope.organizationals[$scope.selectedRow].name

怎么办?感谢,

1 个答案:

答案 0 :(得分:0)

不要传递索引,只需传递对象即可。你不必担心从数组中引用

<tr ng-repeat="organizational in organizationals" ng-class="{'selected':$index == selectedRow}" ng-click="setClickedRow(organizational)">

$scope.setClickedRow = function(organization){
    $scope.selectedOrganization = organization;

}