Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在DOM中添加新元素时使用ng模型_Javascript_Angularjs - Fatal编程技术网

Javascript 在DOM中添加新元素时使用ng模型

Javascript 在DOM中添加新元素时使用ng模型,javascript,angularjs,Javascript,Angularjs,我有一些angular代码,它将一些输入文本框添加到div中。我想将ng module=“…”添加到那些新创建的文本框中,但如果我这样做,它们似乎不会被angular注册为模型 基本上,我试图在运行时创建这些输入框,给它们一个ng model属性,然后创建一个包含模型的div: <input type="text" ng-model="placeholder_name" /> .... <div id="content">{{placeholder_name}}</

我有一些angular代码,它将一些输入文本框添加到div中。我想将ng module=“…”添加到那些新创建的文本框中,但如果我这样做,它们似乎不会被angular注册为模型

基本上,我试图在运行时创建这些输入框,给它们一个ng model属性,然后创建一个包含模型的div:

<input type="text" ng-model="placeholder_name" />
....
<div id="content">{{placeholder_name}}</div>
我找到{…}的所有实例并为它们创建输入框。然后我将{…}替换为
{{}
,其思想是当我更改tet框的值时,这将跨越内容更改

这行正在抛出一个错误。不喜欢我创建ng模型的方式:

<input type="text" class="span2 placeholder" ng-model="placeholder_{{placeholder}}" value="{{placeholder}}" />

错误:语法错误:标记“{”是的第13列的意外标记 表达式[placeholder{{{placeholder}}],起始于 [{{占位符}}]


你为什么不使用
ng repeat
?像这样构造html内容,真的不是角度的方式。我正在从jQuery移植我的js,仍然不知道所有角度的特性。不过我会接受你的建议!我认为如果你发布模型数据,或者任何会触发放置/更改的数据,这会很有帮助还有一些关于你是使用指令还是通用控制器的解释。角度方面的经验法则:不要在javascript代码中使用DOM内容(指令除外,但你稍后会看到)@Yoshi我已经更新了我的问题
<h2>Template: {{template.title}}</h2>
<div class="well well-small">
    <p><strong>Placeholders</strong></p>
    <div class="placeholder-list">
        <span ng-repeat="placeholder in placeholders">  
            <input type="text" class="span2 placeholder" ng-model="placeholder_{{placeholder}}" value="{{placeholder}}" />
            <span ng-show=" ! $last ">&nbsp;</span>
        </span>
    </div>
</div>
<div contenteditable="true" id="content" ng-bind-html="template.content"></div>
Look! {this} is a placeholder.
<input type="text" class="span2 placeholder" ng-model="placeholder_{{placeholder}}" value="{{placeholder}}" />