为什么这不会导致错误?
export class Foo {
a: any;
b: number;
}
export class MyClass {
public data: Array<Foo>;
}
我将一个字符串赋给MyClass的属性,不会导致错误。这不应该导致错误吗?
export class MyComponent {
classyClass: MyClass;
constructor() {
this.classyClass = new MyClass();
}
myFunction = function() {
this.classyClass.data = 'abc';
}
}
答案 0 :(得分:2)
如果您使用
exports.countFruits = functions.database.ref("fruits/{FruitID}").onWrite(event =>{
(...)
var sauces = [];
let ref = admin.database().ref("sauces");
ref.on("child_added", function(snapshot, prevChildKey){
let sauce = snapshot.val();
sauces.push(sauce.id);
});
// -> USE THE COMPLETED ARRAY FOR NEXT ANOTHER PURPOSE
});
然后myFunction = function() {
this.classyClass.data = 'abc';
}
将指向this
的实例,而不指向您的组件。你应该使用:
myFunction