来自控制器的绑定模型

时间:2013-08-07 10:14:08

标签: angularjs

如何从控制器绑定模型?

这是我的代码

angular.module('elnApp')
 .controller('GridCtrl', function ($scope, $http, $routeParams, $location,  
 programService) {
$scope.gridOptions = {
    data: 'myData',
    enablePaging: true,
    showFooter: true,
    totalServerItems:'totalServerItems',
    pagingOptions: $scope.pagingOptions,
    filterOptions: $scope.filterOptions,
    selectedItems: $scope.mySelections,
    multiSelect: false,
    afterSelectionChange: function (data) {
      $scope.program = $scope.mySelections[0];
      $scope.program = $scope.mySelections[0].programId;
      programService.get({
             id: $scope.program
          }, function (result) {
            data = {
              'program': result
            };
          });
      $location.path('/program/edit/'+$scope.program);

    }
};});

编辑html

<form ng-submit="save()">
  <input type="hidden" ng-model="program.program.programId"/>
   <dl>
    <dt>Program Name</dt>
      <dd><input name="programName" type="text" ng-model="program.program.programName"/></dd>
    <dt>Program Content</dt>
  </dl>
  <div class="form-actions">
    <button type="submit">Save</button>
 </div>

当我在切换页面之后选择项目来编辑html时,我无法绑定模型?

我对此感到困惑,请帮忙

1 个答案:

答案 0 :(得分:0)

<div>programName: {{program.program.programName}}</div>