Angular2:ViewChild在类或类体的构造函数中引用?

时间:2016-08-04 12:13:51

标签: angular

什么是最佳做法,区别在于:

ObjectMapper mapper =  new ObjectMapper()
            .enable(SerializationFeature.INDENT_OUTPUT)
            .disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
            .registerModule(new JodaModule())
            .setTimeZone(TimeZone.getTimeZone("GMT-7"));

export class suchPage {
    @ViewChild(SuchDirective) suchDirective:SuchDirective;
}

2 个答案:

答案 0 :(得分:2)

官方文档引用了第一种方法。我猜它是最好的做法:

https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#parent-to-view-child

答案 1 :(得分:0)

第二种方法不起作用,因为debug_printf()注入的元素仅在视图初始化(// Make predictions. BenchmarkUtil.startTime() val predictions = trainModel.transform(testData) predictions.collect() val testTime = BenchmarkUtil.getProcessingTime() println(className + " Prediction time [ms]: " + testTime) )之后可用。