【问题标题】:jSLint with Angular causes Unexpected '$scope' error带有 Angular 的 jSLint 导致意外的“$scope”错误
【发布时间】:2014-07-19 13:12:34
【问题描述】:

当我对正在构建的基于 Angular 的应用程序运行 jSLint 时,我收到“意外的 '$scope'”错误。

以下是导致错误的代码的简化版本。您可以将代码输入jslint.com 网站以重现问题。

我不明白为什么第一个函数声明 (downloadFile) 不会导致错误,但第二个函数声明 (buildFile) 会导致错误。

/*jslint browser: true*/
/*global angular */
angular.module('testApp')
    .controller('FileCtrl', ["$scope", function ($scope) {
        "use strict";
        $scope.downloadFile = function () {
            window.location = '/path/to/file';
        }

        $scope.buildFile = function () {

        }
}]);

【问题讨论】:

    标签: javascript angularjs jslint


    【解决方案1】:

    导致该错误的函数后缺少分号

    $scope.downloadFile = function () {
        window.location = '/path/to/file';
    }; //<-- add semicolon
    
    $scope.buildFile = function () {
    
    }; //<-- add semicolon
    

    【讨论】:

    • 谢谢!这现在更有意义了。我没有想到它,因为 jSLint 通常会告诉您它何时需要半色。
    猜你喜欢
    • 2012-02-29
    • 2016-03-01
    • 1970-01-01
    • 2015-07-30
    • 2015-02-09
    • 2012-10-21
    • 2011-03-01
    • 1970-01-01
    相关资源
    最近更新 更多