Struggling to find up-to-date Angular 2 syntax is a challenge. So, how can we properly connect variables (whether simple or objects) in Angular now that the concept of controller $scope has evolved?
import {Component} from '@angular/core'
@Component({
selector: 'testtag',
templateUrl: './simplecomponent.component.html',
})
export class SimpleComponent {
public myNumber : number = 5;
}
html:
<div>Greetings from the component template! {{myNumber}}</div>
The code functions as expected. I see "5" displayed in the template output. Despite this, most resources suggest using something like this.muNumber = 5;
. Is this approach reserved for plain JavaScript? And does this
hold significance when working with TypeScript? If so, how?
tl;dr: What are the current best practices for one-way and two-way binding in Angular 2 now that the "final" version is available?