【问题标题】:angular state.go not working when minified角度状态。缩小时不工作
【发布时间】:2018-04-17 00:13:47
【问题描述】:

我们使用 gulp 来缩小 js 文件。

在我的项目中,我有 config.js,其中包含以下代码。

var routerApp = angular.module('MyApp');
routerApp.config(function ($stateProvider, $urlRouterProvider, APPCONSTANTS, $sceProvider) {

    //$urlRouterProvider.otherwise('/home');

    $stateProvider        
        .state('myState', {
            url: '',

            templateUrl: 'SomePath' + 'index.html',            
            controller: 'myController'
        });

    $sceProvider.enabled(false);
});
routerApp.controller("myStartController", function ($state) {
    $state.go("myState");
})

并且 index.cshtml 包含以下代码

<html ng-app="MyApp">
<head>
..Contains required links
</head>
<body>
    <div ng-controller="myStartController">@*this to call state.go*@</div>
    <div ui-view style="height: calc(100% - 64px);"></div>
</body>
</html>

如果没有缩小中断,这可以正常工作。没有收到任何具体错误。

【问题讨论】:

标签: angularjs


【解决方案1】:

在您的所有注册(configcontroller 等)中,使用以下语法:

routerApp.config(['$stateProvider', '$urlRouterProvider', 'APPCONSTANTS', '$sceProvider', function ($stateProvider, $urlRouterProvider, APPCONSTANTS, $sceProvider) {    
    // Your code
}]);

routerApp.controller("myStartController", ['$state', function ($state) {
    // Your code
}]);

这被称为Inline Array Annotation

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-03-16
  • 2021-01-08
  • 2013-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-15
  • 1970-01-01
相关资源
最近更新 更多