ajax通过JSF更新AngularJS后,AngularJS停止工作
我有以下JSF+AngularJS表单:ajax通过JSF更新AngularJS后,AngularJS停止工作,angularjs,jsf,primefaces,Angularjs,Jsf,Primefaces,我有以下JSF+AngularJS表单: <h:form id="fmMain1" enctype="multipart/form-data" prependId="false"> <p:commandButton value="Edit" action="#{testBean.updateMode}" update="@form" process="@form"/> <h:panelGrid rendered="#{testBea
<h:form id="fmMain1" enctype="multipart/form-data" prependId="false">
<p:commandButton value="Edit" action="#{testBean.updateMode}"
update="@form" process="@form"/>
<h:panelGrid rendered="#{testBean.mode eq 'EDIT'}">
<input ng-show="true" type="text" ng-model="sometext" />
<h1>Hello {{ sometext }}</h1>
</h:panelGrid>
<h:panelGrid rendered="#{testBean.mode eq 'VIEW'}">
<input ng-show="true" type="text" ng-model="sometext" />
<h1>Hello {{ sometext }}</h1>
</h:panelGrid>
</h:form>
这在第一次呈现页面时有效。但它在单击“编辑”按钮后停止工作,ajax通过JSF更新表单。这是如何造成的,我如何解决它?这里的问题是,在ajax调用new html之后,我们需要再次编译新DOM,如下所示:
$scope.compileHTML = function($el) {
($compile($el))($scope);
$scope.$apply();
};
在此之后,请拨打此电话:
$('#dest').load('replace.html', function() {
$dest.scope().compileHTML($dest);
});
scope()函数允许为HTML元素找到正确的AngularJS范围。它不需要直接指向带有ng控制器的元素,ng控制器下的任何元素都可以使用
$('#dest').load('replace.html', function() {
$dest.scope().compileHTML($dest);
});