到目前为止,我设法以这种方式实例化了 Component。
创建cli.ts 来测试Angular组件的独立创建:
import 'reflect-metadata';
import { CuComponent } from './app/cu.component';
console.log(new CuComponent())
使用来自tsconfig.json 的一些设置运行tsc:
tsc -t es5 --lib es2016,dom --experimentalDecorators src/cli.ts
得到输出:
CuComponent {
registration:
FormGroup {
validator: null,
asyncValidator: null,
_onCollectionChange: [Function],
_pristine: true,
_touched: false,
_onDisabledChange: [],
controls: { familyName: [Object], givenName: [Object], phone: [Object] },
_valueChanges:
EventEmitter {
_isScalar: false,
observers: [],
closed: false,
isStopped: false,
hasError: false,
thrownError: null,
__isAsync: false },
_statusChanges:
EventEmitter {
_isScalar: false,
observers: [],
closed: false,
isStopped: false,
hasError: false,
thrownError: null,
__isAsync: false },
_status: 'VALID',
_value: { familyName: null, givenName: null, phone: null },
_errors: null } }
组件已创建。