如何在Cordova应用程序中使用ngRoute
我在Cordova应用程序中使用angularJS,而在我的应用程序中尝试使用$route来浏览不同的模块。即使在我的页面中引用了angular route js,我也无法让它运行 这是我的html页面html:如何在Cordova应用程序中使用ngRoute,cordova,visual-studio-cordova,angular-routing,Cordova,Visual Studio Cordova,Angular Routing,我在Cordova应用程序中使用angularJS,而在我的应用程序中尝试使用$route来浏览不同的模块。即使在我的页面中引用了angular route js,我也无法让它运行 这是我的html页面html: <div ng-app="mainApp"> <a href="/module1">module1</a> <a href="/module2">module2</a> <
<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>
我的控制器代码:
在AngularJS cordova应用程序中使用$route的解决方案如下: 1) 在html页面中引用angular-route.js。 2) 添加ngRoute作为模块的依赖项(这是缺少的部分) 在我的mainApp模块中,我需要添加ngRoute,以在加载模块时加载ngRoute功能,因此我引用$route的控制器代码将起作用 更新的模块实例化:
希望这有帮助。在AngularJS cordova应用程序中使用$route的解决方案如下: 1) 在html页面中引用angular-route.js。 2) 添加ngRoute作为模块的依赖项(这是缺少的部分) 在我的mainApp模块中,我需要添加ngRoute,以在加载模块时加载ngRoute功能,因此我引用$route的控制器代码将起作用 更新的模块实例化: 希望这有帮助
// 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;
});
angular.module("mainApp",
[
'module1',
'module2',
'ngRoute',
]
);