Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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
如何将表达式的值传回angular2中的数据目标?_Angular_Typescript_Angular2 Template - Fatal编程技术网

如何将表达式的值传回angular2中的数据目标?

如何将表达式的值传回angular2中的数据目标?,angular,typescript,angular2-template,Angular,Typescript,Angular2 Template,我试图将元素的id传递回我的目标。我的页面上有多个ace编辑器实例。我想知道哪一个正在向我发送“textchanged”事件,以便我可以同步数组中正确元组的内容 <md-grid-tile *ngFor="let card of function_cards"> <md-card> Some content here. <pre>{{card.code}}</pre> <pre>{{card.id

我试图将元素的id传递回我的目标。我的页面上有多个ace编辑器实例。我想知道哪一个正在向我发送“textchanged”事件,以便我可以同步数组中正确元组的内容

<md-grid-tile *ngFor="let card of function_cards">
    <md-card>
        Some content here.
    <pre>{{card.code}}</pre>
    <pre>{{card.id}}</pre>

    <div ace-editor 
       [text]="code"
       [mode]="'python'"
       [theme]="'eclipse'"
       [options]="options"
       [readOnly]="false"
       [autoUpdateContent]="true"
       (textChanged)="onChange($event)"
       style="min-height: 200px; 
       width:100%; 
       overflow: auto;" 
       (click) = "setId({{card.id}})"></div>
    </md-card>
</md-grid-tile>

此实现不起作用。我似乎不知道出了什么问题。还有,这是最好的方法吗?我需要跟踪在不同ng2 ace编辑器实例中所做的更改。

您可以在onChange事件中发送卡id:

您可能遇到的问题是,在单击处理程序中有这些{{括号,而这些括号在此处不是必需的。这将起作用:


但是我认为您不需要此功能。希望这有帮助!

您可以在onChange事件中发送卡id:

您可能遇到的问题是,在单击处理程序中有这些{{括号,而这些括号在此处不是必需的。这将起作用:


但是我不相信你需要这个函数。希望这有帮助!

这是有效的。{{括号导致了问题。我使用了你的第一个建议。谢谢。这是有效的。{括号导致了问题。我使用了你的第一个建议。谢谢。
private function_cards: CodeEditor[] = [{
    id: 1, 
    code: "something"
},
{
    id: 2,
    code: "something else"
}];

setId(id: number){
    this.text_editor_id = id;
    console.log("CLICKED ON: " + id)
}

onChange(code) {
    console.log("new code", this.text_editor_id);
    this.function_cards[this.text_editor_id].code = code;
}
 (textChanged)="onChange($event, card.id)"
 (click)="setId(card.id)"