我怎样才能让 ngRoute 在 Cordova App 中工作
How can i get ngRoute to work in Cordova App
我在我的 Cordova 应用程序中使用 angularJS,同时我试图在我的应用程序中使用 $route 来浏览不同的模块。即使我的页面中引用了 angular 路由 js,我也无法获得它 运行。
这是我的 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;
});
在AngularJScordova app中使用$route的解决方案如下:
1) 在您的 html 页面中引用 angular-route.js。
2) 添加 ngRoute 作为模块的依赖项(这是缺失的部分)。
在我的 mainApp 模块中,我需要添加 ngRoute 是一个依赖项,以便在加载我的模块时加载 ngRoute 功能,因此我用于引用 $route 的控制器代码将起作用。
更新模块实例化:
angular.module("mainApp",
[
'module1',
'module2',
'ngRoute',
]
);
希望对您有所帮助。
我在我的 Cordova 应用程序中使用 angularJS,同时我试图在我的应用程序中使用 $route 来浏览不同的模块。即使我的页面中引用了 angular 路由 js,我也无法获得它 运行。
这是我的 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;
});
在AngularJScordova app中使用$route的解决方案如下: 1) 在您的 html 页面中引用 angular-route.js。 2) 添加 ngRoute 作为模块的依赖项(这是缺失的部分)。
在我的 mainApp 模块中,我需要添加 ngRoute 是一个依赖项,以便在加载我的模块时加载 ngRoute 功能,因此我用于引用 $route 的控制器代码将起作用。
更新模块实例化:
angular.module("mainApp",
[
'module1',
'module2',
'ngRoute',
]
);
希望对您有所帮助。