Meteor html中的ng2显示对象
我正在尝试解决如何使用angular2在html中显示对象。在ng1中,我分配给一个变量,并在html和bingo中用双括号括住变量名!现在我似乎根本无法显示任何数据 下面是我的简单方法调用:Meteor html中的ng2显示对象,meteor,angular,Meteor,Angular,我正在尝试解决如何使用angular2在html中显示对象。在ng1中,我分配给一个变量,并在html和bingo中用双括号括住变量名!现在我似乎根本无法显示任何数据 下面是我的简单方法调用: onSubmit(value: oSearch): void { console.log('you submitted value: ', value); Meteor.call('methodName',value.type,value.year,value.idNumber, fu
onSubmit(value: oSearch): void {
console.log('you submitted value: ', value);
Meteor.call('methodName',value.type,value.year,value.idNumber, function(error,result) {
if (error) {
console.log('failed', error);
} else {
this.oResult = result[0];
console.log('successful call', this.oResult);
}
})
}
对象被打印到控制台。但我无法使用以下方法进行渲染:
{{oResult}}
oResult是使用
oResult:Object;
对ts和ng2来说是全新的
更新
好吧,我试过NgZone,但没用。我的行为真的不明白
} else {
console.log('successful call', result[0].topItem);
this.oResult = result[0];
console.log('successful call', this.oResult);
两个console.log都正确打印对象,但oResult显示为[object object]
如果我改为:
this.oResult.topItem = result[0].topItem
然后抛出流星错误,第二个console.log无法打印。错误是:
Exception in delivering result of invoking 'methodName': TypeError: Cannot set property 'topItem' of undefined
我的服务器方法与ng1完美配合。我尝试了http的同步版本,但没有改变行为
也许有人知道一个使用更新的angular2 meteor的http方法调用的教程演示,我可以用它来分叉?Angulars无法识别在Angulars区域之外运行的代码更新字段时的值更改。注入
区域:NgZone
并在区域内运行代码。运行(…)
。在Angular中初始化库,使其使用Angular修补的异步API,该API将通知Angular可能的更改,这可能就足够了
constructor(private zone: NgZone) {
}
onSubmit(value: oSearch): void {
console.log('you submitted value: ', value);
Meteor.call('methodName',value.type,value.year,value.idNumber, function(error,result) {
if (error) {
console.log('failed', error);
} else {
zone.run(function() {
this.oResult = result[0];
console.log('successful call', this.oResult);
});
}
});
}
另请参见以获取示例 如果字段由运行在Angulars区域之外的代码更新,Angular无法识别值更改。注入
区域:NgZone
并在区域内运行代码。运行(…)
。在Angular中初始化库,使其使用Angular修补的异步API,该API将通知Angular可能的更改,这可能就足够了
constructor(private zone: NgZone) {
}
onSubmit(value: oSearch): void {
console.log('you submitted value: ', value);
Meteor.call('methodName',value.type,value.year,value.idNumber, function(error,result) {
if (error) {
console.log('failed', error);
} else {
zone.run(function() {
this.oResult = result[0];
console.log('successful call', this.oResult);
});
}
});
}
另请参见以获取示例