[英]Toolbar view is not changed when its data changed?
This is my sample code: stackblitz demo 这是我的示例代码: stackblitz演示
Mark-Up: 加价:
<div>
<ejs-toolbar #element>
<e-items>
<e-item *ngFor="let item of newarray; let i = index" [text]="item.text" [tooltipText]="item.text">
</e-item>
</e-items>
</ejs-toolbar>
</div>
<div>
<div style="margin-top: 5px">
<button style="margin-right: 5px" (click)="run()" type="submit">add</button>
</div>
</div>
<div>
<pre>newarray: {{ newarray | json }}</pre>
</div>
TS: TS:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
newarray = [
{ text: "Cut"}
]
run() {
this.newarray = [
{ text: "Paste" },
{ text: "Underline" },
{ text: "Italic" }]
}
}
Here I have my toolbar component. 这里有我的工具栏组件。 it is rendered through
*ngfor
. 它通过
*ngfor
呈现。 If I change it's data the toolbar view is not updated but data is changing. 如果我更改了数据,则工具栏视图不会更新,但是数据正在更改。
I don't know, how to solve this? 我不知道该如何解决?
Please provide suitable solution for this. 请为此提供合适的解决方案。 Thanks
谢谢
Try something like this: 尝试这样的事情:
Use ToolbarComponent
使用ToolbarComponent
DEMO -----> Solution 演示-----> 解决方案
TS: TS:
import {
Component, OnInit, ViewChild, ElementRef
} from '@angular/core';
import { ToolbarComponent } from '@syncfusion/ej2-ng-navigations';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
@ViewChild('element') el: ToolbarComponent;
newarray: Array<any>;
ngOnInit() {
this.newarray = [
{ text: "Cut" },
{ text: "Copy" },
{ text: "Paste" },
{ text: "Underline" },
]
}
run() {
let ummy: Array<any> = [
{ text: "Paste" },
{ text: "Underline" },
{ text: "Italic" }]
this.el.items = ummy
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.