我在下面添加了一个示例
如果单击添加按钮,“ newarray”变量值将更新,但不会反映出来。我不知道如何解决
这是用于添加新对象的功能:
export class AppComponent {
newarray = [
{ text: "Outdent" }
];
public run() {
this.newarray=[
{ text: "Cut" },
{ text: "Copy" },
{ text: "Paste" },
{ text: "Underline" },
{ text: "Italic" },
{ text: "Color" },
{ text: "Numbering" },
{ text: "Ascending" },
{ text: "Descending" },
{ text: "Indent" },
{ text: "Outdent" },
];
}
}
这是示例链接[运行状态示例]: sample
答案 0 :(得分:2)
您的示例正在更改window.onload=function () {
document.getElementById("theBackgroundImage").style.visibility = "visible";
}
,但是您的模板在newarray
上进行了迭代,但从未更改。这就是为什么您的视图不会更新的原因。
您可以通过在开发过程中将其添加到模板中来实时检查变量:
tbarArray
这将清除对“是否正在更新?”的疑问。将来。
答案 1 :(得分:0)
尝试这样的事情:
使用 ToolbarComponent
演示-----> Solution
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
}
}