[英]angular ng-template did not update after array have data
I using angular to build a form where insert and modify is on same page. 我使用angular构建了一个表单,其中插入和修改在同一页面上。 While I doing insert the form work well however when user enter modify then template did not bind back.
虽然我在插入表单时工作良好,但是当用户输入“ modify”时,模板未绑定回去。
My html:- 我的HTML:-
<table>
<tbody>
<tr ng-repeat="DescEN in tempDescENList" ng-include="getTemplate(DescEN,'EN')">
</tr>
</tbody>
</table>
<script type="text/ng-template" id="ENdisplay">
<td>{{DescEN.Sequence}}</td>
<td>{{DescEN.Type}}</td>
<td>{{DescEN.Detail}}</td>
<td>
<button class="btn btn-warning btn-xs" ng-click="editDesc(DescEN,'EN')">Modify</button>
<button class="btn btn-danger btn-xs" ng-click="deleteDesc(DescEN,'EN')" ng-click="">Delete</button>
</td>
</script>
<script type="text/ng-template" id="ENedit">
<td>{{DescEN.Sequence}}</td>
<td>{{DescEN.Type}}</td>
<td><input type="text" ng-model="DescEN.Detail" /></td>
<td>
<button class="btn btn-info btn-xs" ng-click="saveEditDesc(DescEN,'EN')">Save</button>
<button class="btn btn-primary btn-xs" ng-click="reset(DescEN,'EN')">Cancel</button>
</td>
</script>
My script behind did load the object and i check with console and it's there. 我后面的脚本确实加载了该对象,我通过控制台进行了检查,它在那里。 However it did not bind to my ng-repeat.
但是,它没有绑定到我的ng-repeat。 The weird thing is that after I manual click on add a new line on UI then the the previous data had load.
奇怪的是,在我手动单击UI上的添加新行之后,先前的数据已加载。 For example from .js file i load 3 object into repeater.
例如,从.js文件中,我将3个对象加载到转发器中。 By default the ng-template did not show the 3 object, However after i add one more object by using interface then it show 4 records in my ng-repeat.
默认情况下,ng模板不显示3个对象,但是在我通过使用接口添加了一个对象之后,它在ng-repeat中显示了4条记录。
Question:- How do I make my ng-template to show ENdisplay after binding from js 问题:-从js绑定后,如何使ng模板显示ENdisplay
I had a similar issue, the issue being a race condition. 我有一个类似的问题,这个问题是比赛条件。 Does the template load first from the
$templateCache
via ng-include
or does the data load first... that's the issue you're likely having. 是先通过
ng-include
从$templateCache
templateCache加载$templateCache
,还是先加载数据...这就是您可能遇到的问题。
I solved this with a directive: 我用指令解决了这个问题:
.directive 'taskForm', [
'$parse'
'$http'
'$compile'
'$templateCache'
($parse, $http, $compile, $templateCache)->
dir =
restrict: 'A'
require: 'ngModel'
link: ($scope, elem, attrs, ngModel)->
$scope.task = $parse(attrs.ngModel) $scope
type = $scope.task.task_type
types = [
'type_a'
'type_b'
'type_c'
]
if _.indexOf(types, type) > -1
url = "./views/task.#{type}.html"
$http.get url, {cache: $templateCache}
.then (rsp)->
tmpl = rsp.data
elem.html tmpl
$compile(elem.contents()) $scope
]
Then you can use it like so: 然后,您可以像这样使用它:
<tr ng-repeat="DescEN in tempDescENList">
<td>
<div ng-model="DescEN" task-form></div>
</td>
</tr>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.