来自AngularJS中的局部视图的数据绑定

时间:2016-10-25 05:08:27

标签: angularjs asp.net-mvc

我想将部分视图中的数据绑定到索引,它在同一视图中绑定但不是其他视图。我试过这样的



 nzs = pd.DataFrame(get_matrix_coos(m), 
                    columns=['row_idx', 'col_idx', 'coeff'])

 import matplotlib.pyplot as plt
 import pandas as pd
 import gurobipy as grb
 m = grb.read("miplib/instances/miplib2010/aflow40b.mps.gz")
 nzs = pd.DataFrame(get_matrix_coo(m), 
                    columns=['row_idx', 'col_idx', 'coeff'])
 plt.scatter(nzs.col_idx, nzs.row_idx, 
        marker='.', lw=0)






    $scope.GetDelete = function (cy_name) {
        $scope.items = cy_name;
        //$scope.newItem = { title: '' };
        alert($scope.items);

    }




模态显示但没有数据

1 个答案:

答案 0 :(得分:0)

要使范围变量在模态中可用,模态代码需要落在控制器的范围内。如果它在范围之外定义,则模态模板将不知道范围的存在。

 angular.module('myapp', [])
   .controller('myctrl', function($scope) {


     $scope.GetDelete = function(cy_name) {
       $scope.items = cy_name;
       //$scope.newItem = { title: '' };
       alert($scope.items);
     }
   });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div ng-app='myapp' ng-controller='myctrl' class="modal fade" id="dvDelete" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Are you sure?</h4>
      </div>
      <div class="modal-body">
        <p>{{items}}</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn" data-dismiss="modal">Cancel</button>
        <button type="button" class="btn btn-danger" ng-click="GetDelete('Test')">Delete</button>
      </div>
    </div>
  </div>
</div>
<button type="button" class="btn btn-xs btn-danger margin-inline" data-toggle="modal" data-target="#dvDelete" ng-click="GetDelete('@item.cy_name')"><i class="fa fa-trash"></i>
</button>

这是一个工作代码段