How To bind data using TypeScript Controller & Angular Js

后端 未结 4 1605
余生分开走
余生分开走 2020-11-28 15:57

I am Playing around with Type Script.I have convert my angular js controller to Type Script But i m facing problem in ng-repeater. (I have attached my controller code below:

4条回答
  •  半阙折子戏
    2020-11-28 16:35

    There is one issue with your constructor and $inject - these must fit together

    // wrong
    static $inject = ['$scope', '$http', '$templateCache'];
    constructor (
            private $http,
            private $templateCache
    ){}
    
    // should be
    static $inject = ['$scope', '$http', '$templateCache'];
    constructor (
            private $scope,
            private $http,
            private $templateCache
    ){}
    

    What happened in fact - all params were moved in the meaning, that $http was $scope in fact, etc...

    Simply, $inject array MUST fit to constructor parameter list

    BTW, that's why I had previously here: https://stackoverflow.com/a/30482388/1679310 suggested to use types in the declaration:

       constructor(protected $scope: ICustomerScope,
            protected $http: ng.IHttpService,
            protected $templateCache: ng.ITemplateCacheService)
        { ... }
    

提交回复
热议问题