I am creating a small app using Angular2+Ionic2
. In this app I want initialise google-map
into view segment
when user
There is no built-in support of calling a function when ngSwitch
adds/removes elements.
I would create a directive that calls the function when created (for example in ngOnInit()
) or emits an event where an event handler can be bound to, and apply it to the component that is added when the ngSwitch
branch is enabled.
If ngSwitch
adds a component you can implement it in this component as well (depends on your requirements)
update
Listing
@Directive(selector: '[onCreate]')
export class OnCreate implements OnInit {
@Output() onCreate:EventEmitter = new EventEmitter();
ngOnInit() {
this.onCreate.emit('dummy');
}
}
Plunker example