通過點擊「添加行」按鈕,使用AngularJS添加一行到HTML表格,只需執行像$ scope.photos.push({})之類的操作即可。 。新行包含一個文件輸入字段,我想在新行被渲染後觸發文件輸入字段的文件對話框。這是可能的和如何?Angularjs,在渲染後用ng-repeat做一些HTML元素UI
.controller('mainController', function ($scope) {
$scope.photos = [];
$scope.addPhoto = function(){
$scope.photos.push({});
document.getElementById("photo" + $scope.photos.length-1).click(); // this won't work because the element is not yet rendered.
}
});
HTML
<tr ng-repeat="photo in photos">
<td> <input type="file" id="photo{{ $index }}"> </td>
</tr>
請包括一些代碼。 – 31piy
這是可能的。確保您生成的新行和它的數據存儲在數據庫中。 –
試試這個: - angular.element(document.querySelector('#id'))。click(); –