我有一个这样的类型脚本文件:
class Student {
fullName: string;
constructor(public firstName: string, public middleInitial: string, public lastName: string) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function greeter(person: Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
let user = new Student("Jane", "M.", "User");
document.body.textContent = greeter(user);
我想将它添加到一个角度组件中(恰好在它的打字稿文件中)。 我怎样才能做到这一点? (我已经搜索过,但是没有找到需要的答案)
答案 0 :(得分:0)
您可以做到
创建.ts文件名model.ts
在其中
export interface Person {
firstName: string;
lastName: string;
}
在访问页面,例如:home.ts
导入文件
import * as models_app from '../../models';
设置值
private selectedInstrument: models_app.Person = {
firstName:"chanaka";
lastName:"weerasinghe";
}