gpt4 book ai didi

javascript - 无法访问bind-unsafe-html的ng-model变量的值

转载 作者:行者123 更新时间:2023-11-28 07:02:28 25 4
gpt4 key购买 nike

showdetailsOfInside()内部bind-unsafe-html<内的ng-model变量nameinagein的函数值/strong> 未定义,但我已将文本内容填充到其中。我可以通过 jquery 获取值,但有没有办法通过 Angular js 来做到这一点。

<body ng-controller="AppController" class="container">
Name <input type="text" name="name" ng-model="name" /><br>
Age <input type="text" name="age" ng-model="age"/><br>
<button type="button" class="btn btn-primary" ng-click="showdetailsOfInside()">showdetailsOfInside</button><br>
<div bind-unsafe-html="primaryData"></div>
<body>

bind-unsafe-html="primaryData"的内容

    <button type="button" class="btn btn-primary" ng-click="shownName()">inside Basic</button><br> 
<button type="button" class="btn btn-primary" ng-click="showAge()">inside Primary</button><br>

Name inside <input type="text" name="namein" ng-model="namein" id="nameinside"/><br>
Age indise :: <input type="text" name="agein" ng-model="agein" id="ageinside"/><br>

bind-unsafe-html指令的代码

dynamicContentApp.directive('bindUnsafeHtml', ['$compile', function ($compile) {
return function(scope, element, attrs) {
scope.$watch(
function(scope) {
// watch the 'bindUnsafeHtml' expression for changes
return scope.$eval(attrs.bindUnsafeHtml);
},
function(value) {
// when the 'bindUnsafeHtml' expression changes
// assign it into the current DOM
element.html(value);

// compile the new DOM and link it to the current
// scope.
// NOTE: we only compile .childNodes so that
// we don't get into infinite loop compiling ourselves
$compile(element.contents())(scope);
}
);
};
}]);

最佳答案

如果我是对的,那就是 ng-bind-unsafe-html="primaryData"

关于javascript - 无法访问bind-unsafe-html的ng-model变量的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32003202/

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