我怎样才能让ngRoute在Cordova App中工作

时间:2015-07-14 18:06:59

标签: cordova visual-studio-cordova angular-routing

我在Cordova应用程序中使用angularJS,而我正在尝试在我的应用程序中使用$ route来浏览不同的模块。即使我在页面中引用了角度路径j,我也无法运行它。

这是我的html页面html:

<div ng-app="mainApp">
        <a href="/module1">module1</a>
        <a href="/module2">module2</a>
        <ng-view></ng-view> 

        <pre>$location.path() = {{$location.path()}}</pre>
        <pre>$route.current.templateUrl = {{$route.current.templateUrl}}</pre>
        <pre>$route.current.params = {{$route.current.params}}</pre>
        <pre>$route.current.scope.name = {{$route.current.scope.name}}</pre>
        <pre>$routeParams = {{$routeParams}}</pre>   
    </div>


    <script src="scripts/frameworks/angular.min.js"></script>
    <script src="scripts/frameworks/angular-route.min.js"></script>

这是我的模块定义:

// define all your modules
var module1 = angular.module("module1", []);
var module2 = angular.module("module2", []);

// Lastly, Add all other modules after defining the main module
angular.module("mainApp",
    [
        'module1',
        'module2',

    ]

    );

我的控制器代码:

module1.controller("MainCtrl", function ($scope, $route, $routeParams, $location) {

    $scope.Test = "This is a test message...";


    $scope.$route = $route;
    $scope.$location = $location;
    $scope.$routeParams = $routeParams;

});

1 个答案:

答案 0 :(得分:0)

在AngularJS cordova app中使用$ route的解决方案如下: 1)在你的html页面中引用angular-route.js。 2)添加ngRoute作为模块的依赖项(这是缺失的部分)。

在我的mainApp模块中,我需要添加ngRoute是在加载我的模块时加载ngRoute功能的依赖,因此我的控制器代码用于引用$ route将起作用。

更新模块实例化:

angular.module("mainApp",
    [
        'module1',
        'module2',
        'ngRoute',
    ]

    );

希望这有帮助。