0

Upgrade AngularJS controller to Angular 2.

export default {
    template: html,
    bindings: {
        binding1: '<',
        binding2: '<',
        binding3: '<'
    },
    controller: [SomeService, controller]
}

function controller(SomeService) {
    // code
}

I want to convert this to Angular 2 Component

export class TestComponent implements OnInit {
    constructor(){}
}

How to replace bindings ?

Prog_CS
  • 33
  • 1
  • 6

1 Answers1

1
@Component({
    template: html,
    selector: 'wasnt-shown-in-ngJS-example',
})
export class TestComponent {
    @Input() binding1: number;
    @Input() binding2: string;
    @Input() binding3: Foobar | null;

    constructor(private someSrv: SomeService){
    }

}

Is this what you're looking for?

Ron Newcomb
  • 2,886
  • 21
  • 24
  • I tried to do the samething, But I am getting undefined for bindings value. – Prog_CS Dec 14 '18 at 18:45
  • They will be undefined in the constructor, but will first have value in the ngOnInit() function. If not, check the parent element and its syntax. The kebab-case vs camelCase issue in particular. – Ron Newcomb Dec 14 '18 at 18:51