gpt4 book ai didi

javascript - Angularjs 绑定(bind)在注入(inject) html 时不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:48:22 25 4
gpt4 key购买 nike

我试图查看 documentation但似乎我错过了一些东西。我正在尝试注入(inject)绑定(bind)到 json 的 html。如果声明了 html,它工作正常,但是当我注入(inject)它时,尽管调用了 $compile,它还是不工作。这是代码

<!DOCTYPE html>
<html ng-app>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"> </script>
<script src="todo.js"></script>
<script>

function TodoCtrl($scope)
{
$scope.todos = [{text:'LearnAngularJS'}, {text:'Unlearn Angular'},];
}

$(document).ready(function()
{
$('#div1').html(
$compile('<div ng-controller="TodoCtrl"><ul><li ng-repeat="todo in todos" compile="text">{{todo.text}}<li><ul><div>')(scope));
});

</script>
</head>
<body>
<div ng-controller="TodoCtrl">
<ul>
<li ng-repeat="todo in todos">
{{todo.text}}
<li>
<ul>
</div>

<div id="div1">
<div>

</body>
</html>

最佳答案

http://plnkr.co/edit/NQQBgQKBWEqKHxGwnI0h?p=preview

正如 Ajay 指出的那样,您必须将范围之一与模板相关联。

关于javascript - Angularjs 绑定(bind)在注入(inject) html 时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16185683/

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