我正在使用angularjsangular-ui-router创建chrome应用程序。

app.js

var foo = angular.module('foo', [
    'ui.router',
])
.config(['$stateProvider', '$locationProvider',
    function($stateProvider, $locationProvider) {

    console.log("This works fine.");

    $stateProvider
        .state('login', {
            url: '/',
            templateUrl: 'modules/login/templates/login.html',
            controller: 'loginController'
        })

}])


login.js

foo.controller('loginController',
    ['$scope',
    function($scope){

    console.log("This should be printed on the console.");

}])


window.html

<!DOCTYPE html>
<html ng-app="mycurechrome">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="components/chromestrap/js/jquery-2.0.3.min.js"></script>
    <script src="components/chromestrap/js/bootstrap.min.js"></script>

    <script src="bower_components/angular/angular.min.js"></script>
    <script src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>

    <script src="app.js"></script>
    <script src="modules/login/controllers/login.js"></script>

    <link href="components/chromestrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="css/window.css" rel="stylesheet">

</head>
<body>
    <div ui-view></div>
</body>
</html>


manifest.json

{
    "name": "foo",
    "description": "bar",
    "version": "0.1",
    "manifest_version": 2,
    "app": {
        "background": {
            "scripts": [
                "background.js"
            ]
        }
    },
    "icons": { "16": "icon-16.png", "128": "icon-128.png" }
}


background.js

chrome.app.runtime.onLaunched.addListener(function() {
    chrome.app.window.create('window.html', {
        'outerBounds': {
            'width': 1000,
            'height': 600
        }
    });
});


app.js上,console.log("This works fine.");被执行,但是在login.js上的log()不是。

我不认为我使用ui-router是错误的,但我对此表示怀疑,因为对于Google chrome应用程序可能会有不同的方法。

最佳答案

尝试导航到登录状态,如果它是您的默认状态,请尝试:

.config(['$stateProvider', '$locationProvider', '$urlRouterProvider',
    function($stateProvider, $locationProvider, $urlRouterProvider) {

    console.log("This works fine.");
    $urlRouterProvider.otherwise('/login');
    $stateProvider
        .state('login', {
            url: '/login',
            templateUrl: 'modules/login/templates/login.html',
            controller: 'loginController'
        });

}]);

关于javascript - Angular UI路由器在Chrome应用程序上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36857780/

10-12 13:13