2017-04-26 59 views
0

我有一個帶有電視節目數據的表格。我使用dir-paginate/ng-repeat填充表格,我可以單擊一行打開模式,以便能夠編輯節目,但ng模型數據不會在該模式中的文本框中加載。Angular Modal Text Boxes沒有使用ngModel填充

<tr id='schedule_row' class='hover_click_cell' dir-paginate='tv_show in tv_shows | orderBy:sortType:sortReverse | itemsPerPage:10'> 
<td class='center_text clickable_cell cell_width' ng-click='alter_show(tv_show)'>{{tv_show.show_name}}</td> 

單擊時,它會調用該函數alter_show()

$scope.alter_show = function(show) 
{ 
    $scope.edit_show = show; 
    var modalInstance = $uibModal.open ({ animation: $controller.animationsEnabled, 
               ariaLabelledBy: 'modal-title', 
               ariaDescribedBy: 'modal-body', 
               templateUrl: 'edit_tv_show.html', 
               controller: 'EditTvShowCtrl', 
               controllerAs: '$controller', 
               size: 'sm', 
               backdrop: 'static', 
               keyboard: false 
             }); 

    modalInstance.result.then(function (action) 
    { 

    }, 
    function() { 
    }); 
} 

在JSON形式傳遞看起來像這樣的數據:

{"watched":false,"id":1,"show_name":"The Walking Dead","season":1,"episode":1,"season_episode":"Season 1, Episode 1","$$hashKey":"object:4"} 

我通過在節目細節,將其設置爲$scope.edit_show對象。傳遞的數據不是空的,但是當打開模式時,文本框不會被填充。這些是輸入框:

$scope.edit_show = { 
    show_name: '', 
    season: 0, 
    episode: 0, 
    watched: 0 
}; 

<div class='form-group'> 
<label for='show_name'>Show Name:</label> 
<input type='text' class='form-control' id='edit_show_name' ng-model='edit_show.show_name'> 
</div> 

<div class='form-group'> 
<label for='season'>Season:</label> 
<input type='number' class='form-control' id='edit_season' ng-model='edit_show.season'> 
</div> 

我怎樣才能得到這個填充已被點擊的行中的細節的文本框?

+0

文本框沒有填充或值沒有綁定? –

回答

0

我已經設法弄清楚了使用modalInstance的解決方案。

$scope.alter_show = function(show) 
{ 
    var modalInstance = $uibModal.open ({ animation: $controller.animationsEnabled, 
               ariaLabelledBy: 'modal-title', 
               ariaDescribedBy: 'modal-body', 
               templateUrl: 'edit_tv_show.html', 
               controller: 'EditTvShowCtrl', 
               controllerAs: '$controller', 
               size: 'sm', 
               backdrop: 'static', 
               keyboard: false, 
               resolve: { tv_show : function() { return show; } } 
             }); 

    modalInstance.result.then(function (action) 
    { 

    }, 
    function() { 
    }); 
} 

angular.module('ui.bootstrap').controller('EditTvShowCtrl', function ($uibModalInstance, $scope, tv_show) 
{ 
    var $controller = this; 

    $scope.edit = tv_show; 
});