gpt4 book ai didi

javascript - Angular ng-controller 与 ng-app 冲突

转载 作者:行者123 更新时间:2023-12-03 10:24:36 25 4
gpt4 key购买 nike

我正在尝试使用自定义控件来获取 Angular 中的可内容编辑元素,如 this example 中所述。 。但是,我还需要使用一个 Controller ,即使我的 Controller 完全为空,它也会导致代码的 contenteditable 部分失败。

This Plunker显示所需的行为,但不包括 Controller 。

<body ng-app="myApp">
<div>
<h1 contenteditable ng-model="test">123</h1>
<textarea ng-model="test"></textarea>
</div>
</body>

This Plunker显示了将 Controller 添加到 HTML 文件第 10 行的 div,但是第一个 Plunker 的所需行为已不复存在。

<body ng-app="myApp">
<div ng-controller="mainController">
<h1 contenteditable ng-model="test">123</h1>
<textarea ng-model="test"></textarea>
</div>
</body>

最佳答案

您必须向应用程序显式注册 Controller - 默认情况下不允许全局 Controller 功能:

.controller("mainController", function mainController($scope){

});

现在这是 Angular v1.3+ 中的默认选项

(当然,绑定(bind)到不受信任的 HTML 时还会遇到其他问题,但那是另一回事了)

关于javascript - Angular ng-controller 与 ng-app 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29461378/

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