我在我的HTML以下行:AngularJS - NG-绑定HTML的不安全和NG-模型问题
<div ng-bind-html-unsafe="departmentConfig" class="control-group"></div>
我用一个$resource
去取回HTML,指定的HTML $scope.departmentConfig
,然后视图完全更新。分配给$scope.departmentConfig
的HTML包含表单元素,其中包含ng-model
属性,但是当我更改这些输入元素中的值时,它们根本不会更新$scope
模型。
这是我曾经尝试过,基于很多其他互联网帖子,和它不工作:
$resource('resources/sources/departments/:mappedName', {
mappedName:departmentKey
}).get(function(departmentConfig) {
// This will call another function that will build a chunk of HTML
$scope.departmentConfig = $scope.buildDepartmentConfigHtml(departmentConfig);
// This is my feeble attempt to access the element, and bootstrap it to include the items in the $scope model.
var $departmentConfigContainer = $('#departmentConfig');
angular.bootstrap($departmentConfigContainer, ['sourcemanager']);
我甚至看到了一些的jsfiddle示例,其中这似乎是工作,但我不是。我是否过早地称自举?我也试过把一个$watch
上$scope.departmentConfig
这样的:
$scope.$watch('departmentConfig', function() {
var $departmentConfigContainer = $('#departmentConfig');
angular.bootstrap($departmentConfigContainer);
});
,但它也不能工作。我敢打赌,对此我有一个简单的解释,我似乎无法得到ng-model
的输入元素,这些输入元素在页面编译后加载以绑定到模型。任何帮助表示赞赏,这是我需要在我的页面上工作的最后一项功能。让我知道你是否还需要更多关于我的配置的信息。
所以,简单地说,我知道它已被加载后,如何强制一段DOM重新编译?
UPDATE
这是一个概括的jsfiddle我想做些什么:http://jsfiddle.net/j_snyder/ctyfg/。你会注意到属性2和属性3不更新模型,我在外部div上调用bootstrap,希望这会包含模型绑定中的那些。这是我第一次发布到jsfiddle,如果你看不到这个例子,请告诉我。
感谢安迪。我还在Angular Google Group上发布了帖子,这里是主题。我找到了一些可以做到我需要的东西,就像你刚刚发布的那样。 https://groups.google.com/forum/?fromgroups#!topic/angular/51-CNL6GEKE –