javascript - Angularjs $routeProvider jshint 错误

标签 javascript angularjs jshint

我有这个 Angular 代码

    (function() {
        'use strict';

        var sampleApp = angular.module('MyApp', [
            'ngRoute',
            'MyApp.controllers.Main'
        ]);

        sampleApp .config(['$routeProvider',
            function($routeProvider){
                $routeProvider.

                    when('/',{
                        templateUrl: '../templates/home.html',
                        controller: 'homeController'
                    }).

                    when('/one',{
                        templateUrl: '../templates/one.html',
                        controller: 'oneController'
                    }).

                    when('/two',{
                        templateUrl: '../templates/two.html',
                        controller: 'twoController'
                    }).
        }]);

    })();   

当我使用 jshint 时,我收到这些错误。

    src/app/app.js: line 27, col 5, Expected an identifier and instead saw '}'.
    src/app/app.js: line 27, col 5, Expected an assignment or function call and instead saw an expression.
    src/app/app.js: line 27, col 6, Missing semicolon.
    src/app/app.js: line 27, col 6, Expected an identifier and instead saw ']'.
    src/app/app.js: line 27, col 6, Expected an assignment or function call and instead saw an expression.
    src/app/app.js: line 27, col 7, Missing semicolon.
    src/app/app.js: line 27, col 7, Expected an identifier and instead saw ')'.
    src/app/app.js: line 27, col 7, Expected an assignment or function call and instead saw an expression.
    src/app/app.js: line 29, col 2, Expected ']' to match '[' from line 9 and instead saw ')'.
    src/app/app.js: line 29, col 5, Expected ')' and instead saw ';'.
    src/app/app.js: line 29, col 6, Missing semicolon.
    src/app/app.js: line 1, col 13, Unmatched '{'.
    src/app/app.js: line 29, col 10, Unrecoverable syntax error. (100% scanned).

我看不出如何更改 Angular 以传递 jshint

最佳答案

    when('/two',{
                    templateUrl: '../templates/two.html',
                    controller: 'twoController'
                }).

最后一个“.”应该是一个“;”相反,它应该看起来像

     when('/two',{
                    templateUrl: '../templates/two.html',
                    controller: 'twoController'
                });

关于javascript - Angularjs $routeProvider jshint 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38212480/

相关文章:

javascript - 如何将 DOM 的值和属性放入文本框中?

javascript - AngularJS/Protractor : Error while running the protractor with the angular seed basic app?

autocomplete - 为支架中的 Electron 启用jshint

javascript - jshint 期望新的 'prefix' 用于函数

javascript - 在 ui-sref 中过滤

javascript - 扩展全局配置,jshint

javascript - 如何禁用下拉选择中的一个选项?

javascript - jQuery attr() 无法设置属性

javascript - Backbone : populate multiple drop-downs with the same data?

angularjs - Angular 和 Google 标签管理器 (GTM) gtm.click