【发布时间】:2014-12-20 15:37:18
【问题描述】:
我想有一个对象作为我的路线的参数,但我从一个数字开始测试路线,但它不起作用。
这是我的路线:
// configure our routes
app.config(function($routeProvider, $locationProvider) {
$routeProvider
// route for the home page
.when('/', {
controller : 'ApplicationController',
templateUrl : './includes/home/home.html',
})
.when('/voir_message/:message', {
templateUrl : './includes/messages/voir_message.html',
controller : 'VoirMessagesController',
controllerAs : 'controller'
})
.otherwise({redirectTo : '/'});
// use the HTML5 History API
$locationProvider.html5Mode(true);
});
我的控制器:
app.controller('VoirMessagesController', function($scope, $rootScope, $location, userService, dataRefreshServices){
$scope.message = $routeParams.message;
});
当我需要改变我使用的路线时:
$location.path('voir_message/1');
这不起作用,当我点击我的链接(调用 javascript 函数并调用此行)时,我的页面被重定向到 file:///
1 - 为什么?如果我删除路由中的“/1”和“:message”(所以不传递任何参数)它工作正常。
2 - 如果我需要放置我的对象,我可以只放置“JSON.stringify(myObject)”而不是“1”吗?
3 - 最后一个关于我的路线的问题,为什么地址以“file:///”开头?例如,索引页面是“file:///”(我使用的是 nodewebkit),所以当我加载应用程序时出现以下错误:
Failed to load resource: net::ERR_FILE_NOT_FOUND file:///
我发现问题出在我的主路由上,如果我更改“redirectTo: '/' url 更好但仍然有错误:
.when('/home', {
controller : 'ApplicationController',
templateUrl : './includes/home/home.html',
})
.otherwise({redirectTo : '/home'});
编辑我的申请:
var app = angular.module('client', ['ngRoute', 'pascalprecht.translate']);
在我的 index.html 中这样使用:
<html xmlns="http://www.w3.org/1999/xhtml" data-ng-app="client">
【问题讨论】:
-
请注意:您在控制器中注入了两次 $routeParams
-
已修复,但没有任何改变
-
如何通过浏览器访问您的应用程序?
-
您是否将
ngRoute注入到您的应用程序和所有需要的基本组件中?换句话说,需要更多的代码,否则我猜。 -
我已经注入了 ngRoute 是的,我粘贴了我的模块的代码。路线在没有参数的情况下工作
标签: javascript angularjs node-webkit