【问题标题】:Uncaught ReferenceError: angular is not defined using type script未捕获的 ReferenceError:未使用类型脚本定义角度
【发布时间】:2015-08-15 02:13:02
【问题描述】:

我正在使用 Type Script 和 Angular js 我已经实现了一个控制器,它命名为快速搜索,并且我正在尝试执行搜索操作。我正在从我的 aspx 的文本框中获取搜索词,然后在 ng 单击时,它将转到我的控制器,然后它将数据放入 web api 方法,然后将结果返回到网格中。 但我面临问题是因为 未捕获的 ReferenceError:未定义角度 我在下面写了我的控制器代码:-

/// <reference path="../interface/interface.ts" />
/// <reference path="../../scripts/typings/jquery/jquery.d.ts" />
/// <reference path="../../scripts/typings/angularjs/angular.d.ts" />
module CustomerSearch.CustomerCtrl {
    export class CustomerCtrl {
        static $inject = ['$scope', '$http', '$templateCache'];

        constructor(protected $scope: ICustomerScope,
            protected $http: ng.IHttpService,
            protected $templateCache: ng.ITemplateCacheService) {
            $scope.search = this.search;
            console.log(angular.element($scope).scope());
        }
        public search = (search: any) => {
            debugger;
           var Search = {
                ActId: search.txtAct,
                checkActiveOnly: search.checkActiveOnly,
                checkParentsOnly: search.checkParentsOnly,
                listCustomerType: search.listCustomerType
            };

            this.$scope.customer = [];
            this.$scope.ticket = [];
            this.$scope.services = [];


            this.$http.put('<%=ResolveUrl("/API/Search/PutDoSearch")%>', Search).
                success((data, status, headers, config) => {
                debugger;
                this.$scope.cust_File = data[0].customers;
                this.$scope.ticket_file = data[0].tickets;
                this.$scope.service_file = data[0].services;
            }).
                error((data, status) => {
                console.log("Request Failed");
                });

        }
    }
    var customerapp = angular.module("CustomerSearch", []);
    customerapp.controller('CustomerCtrl',["$scope", CustomerCtrl]);

}

【问题讨论】:

  • What is the cause for "angular is not defined" 的可能副本 -- 确保在运行代码之前包含 angular 脚本文件
  • 您可以将customerapp.controller('CustomerCtrl',["$scope", CustomerCtrl]);更改为customerapp.controller('CustomerCtrl', CustomerCtrl);,因为您使用的是$inject
  • 很高兴看到你的回复@Brocco,但它仍然无法正常工作
  • Mico,你能展示一下你是如何加载角度的吗?
  • @DavidSherret 我刚刚给出了 JSCrip 的参考路径

标签: angularjs angularjs-scope typescript typescript1.4 typescript1.5


【解决方案1】:

我通过更改我的 java 脚本引用的顺序解决了这个问题。 如:-

1.jquery-latest.js
2.app.module.js" 
3.Controller.js" 
4.Interface.js" 
5.angular.js" 
6.angular.min.js" 
7.app.routes.js"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    相关资源
    最近更新 更多