Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Sometimes you need to access the underlying Titanium view/proxy of template elements. To do so you can use the ViewChild/ViewChildren decorators from Angular in combination with the AfterViewInit lifecycle hook. First assign a template reference variable to the element you want to access and then retrieve the Titanium object instance via the .nativeElement.titaniumView property.

Code Block
linenumberstrue
languagejs
@Component({
  template: `
    <Label #myLabel></Label> 
  `
})
class MyComponent implements AfterViewInit {
  @ViewChild('myLabel') labelRef: ElementRef;

  ngAfterViewInit() {
    const myLabel = this.labelRef.nativeElement.titaniumView as Titanium.UI.Label;
    myLabel.center = {x: 50, y: 50};
  }
}

...