What is best practice to create an AngularJS 1.5 component in Typescript?

前端 未结 7 1761
北荒
北荒 2021-01-30 02:20

I am experimenting with the .component() syntax in Angular 1.5.

It seems that the latest fashion is to code the controller in-line in the component rather t

7条回答
  •  灰色年华
    2021-01-30 03:08

    I'm using the following pattern to use angular 1.5 component with typescript

    class MyComponent {
        model: string;
        onModelChange: Function;
    
        /* @ngInject */
        constructor() {
        }
    
        modelChanged() {
            this.onModelChange(this.model);
        }
    }
    
    angular.module('myApp')
        .component('myComponent', {
            templateUrl: 'model.html',
            //template: `
    `, controller: MyComponent, controllerAs: 'ctrl', bindings: { model: '<', onModelChange: "&" } });

提交回复
热议问题