gpt4 book ai didi

javascript - 为什么 Angular 无法获取输入的 ng-models 值,$sce.trustAsHtml 插入的 html?

转载 作者:行者123 更新时间:2023-11-28 06:52:16 26 4
gpt4 key购买 nike

我的 Controller 上有此代码:

angular.module('reporteadorApp')
.controller('sidebarCtrl', ['$scope', '$http', '$cookies', '$sce', function ($scope, $http, $cookies, $sce) {
$scope.codeControles = '<div class="row"><div class="col-sm-12">'
$scope.codeControles += '<div class="form form-group"><label>' + asignarListaControles.nombreControl + '</label><select class="form form-control" ng-model="' + asignarListaControles.variable1 + '"></select></div>';
$scope.codeControles += '</div></div>';
$scope.codigoHTML = $sce.trustAsHtml($scope.codeControles);
}]);

然后在我的 HTML 中:

<div ng-bind-html="codigoHTML"></div>

我正在尝试将 ng-models 的值插入到我的 View 中,但我不能, Angular 返回未定义。有什么问题?!。如果我手动添加输入并分配 ng -model,可以获取其值。

此外,我无法使用 ng-repeat 将数据添加到此选择

谢谢

最佳答案

最后我解决了我的问题:

var htmlToInsert = $compile('<div>' + $scope.codeControles + '</div>')($scope);
$('#yourDivName').html(htmlToInsert);

然后在我的 HTML 中:

<div id="yourDivName"></div>

;)

关于javascript - 为什么 Angular 无法获取输入的 ng-models 值,$sce.trustAsHtml 插入的 html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32855523/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com