0

I am trying to fetch my all dropdown at page load using ANgularJs+TypeScript.I am done with implementing ng-options and ng-init method to load it but there might me some problem thats why i am not able to get my data from my API or to give call to my API.I have given my Code with this question.

Here is my typescript Controller:-

/// <reference path="../interface/interface.ts" />
/// <reference path="../../scripts/typings/jquery/jquery.d.ts" />
/// <reference path="../../scripts/typings/angularjs/angular.d.ts" />

module CustomerNew.controllers {
    export class CreateCustomerCtrl {
        static $inject = ['$scope', '$http', '$templateCache'];
        debugger;
        constructor(protected $scope: ICustomerScope,
            protected $http: ng.IHttpService,
            protected $templateCache: ng.ITemplateCacheService) {
            $scope.create = this.create;
            $scope.getFormData = this.getformData;
        }
        public getformData: (getFormData: any) => {
            $http.get();
        }

Giving Error AS It's giving error of "Property or signature expected" & Unexpected token. "A constructor, method, accessor, or property was expected". Updated Error

Shian JA
  • 848
  • 4
  • 15
  • 52
  • What are you errors ? You just give us all your code without explainations. It's pretty easy to see that there is errors in your code. For example : `$http.get('./Deskt...` when you use `[HttpPut]`, shouldn't it be `$http.put` ? If you want a good answer explain your problem. – antoinestv Jun 30 '15 at 08:56
  • @Antoine Esteve i have updated my code as well and Yes It's giving error of "Property or signature expected" & Unexpected token. "A constructor, method, accessor, or property was expected". . – Shian JA Jun 30 '15 at 09:02

1 Answers1

1

We need this. and "=" to assign getformData

 constructor(protected $scope: ICustomerScope,
        protected $http: ng.IHttpService,
        protected $templateCache: ng.ITemplateCacheService) {
        $scope.create = this.create;
        $scope.getFormData = this.getformData;
 }
 //public getformData: (getFormData: any) => {
 public getformData = (getFormData: any) => {
    // instead of this notation
    // $http.get(...
    // we need to use this.
    this.$http.get(...
 }

This could be some more complex example of the above TypeScript controller defintion:

module CustomerNew.controllers
{
    export interface ICustomerScope extends ng.IScope
    {
        create: Function;
        getFormData: Function;
    }
    export class CreateCustomerCtrl {
        static $inject = ['$scope', '$http', '$templateCache'];
        debugger;
        constructor(protected $scope: ICustomerScope,
            protected $http: ng.IHttpService,
            protected $templateCache: ng.ITemplateCacheService) {
            $scope.create = this.create;
            $scope.getFormData = this.getformData;
        }
        public getformData = (getFormData: any) =>
        {
            this.$http.get("url"); // ...
        }
        public create = () => { }
    }
}

Check it in this typescript playground compiler/transpiler

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Problem is not solved please see the updated error image – Shian JA Jun 30 '15 at 09:32
  • I added complete code snippet and a link to playground, where you can play with and check what would and what not compile/transipler... – Radim Köhler Jun 30 '15 at 09:41
  • Radim need your help on http://stackoverflow.com/questions/31287908/angularjstypescript-how-to-get-the-selected-index-value-in-ng-select – Shian JA Jul 08 '15 at 11:05
  • Hi, Mico... I will check it during the day... but I cannot guarantee that I will know how to... just to be sure that you understand my limitations ... ;) – Radim Köhler Jul 08 '15 at 11:07
  • @Mico *I tried to make your scenario working, hope it helps a bit... have to get out now...* – Radim Köhler Jul 08 '15 at 11:34