【发布时间】:2016-01-30 03:25:07
【问题描述】:
我正在尝试通过使用将替换 ajax 的 angular 添加到我的 rails 应用程序中的特定页面的路由来学习路由。以下是控制台错误。
未捕获的错误:[$injector:modulerr] 无法实例化模块 testApp 由于:TypeError: Cannot read property 'state' of undefined
这是我定义的。
app.js
app = angular.module("testApp", ['ui.router']);
app.config([
function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('mylistings', {
url: '/mylistings',
templateUrl: '/views/mylistings.html',
controller: 'dashboardCtrl'
});
}
]);
app.controller('dashboardCtrl', function ($scope, $http, $stateParams) {
$scope.testing="testdata"
});
mylistings.html
{{testing}}
在这种情况下,http://localhost:3000/dashboard 是我要路由的 url。有人可以告诉我这里做错了什么。
【问题讨论】:
-
配置中没有显示 url
/dashboard。 -
@charlietfl 我希望它类似于localhost:3000/dashboard#mylistings...
-
localhost:3000/dashboard 来自我的 Rails 应用程序,而不是角度。我想在这里路由,因为我想要一个不同的部分 localhost:3000/dashboard#mybookings 和其他一些
-
应该有一个使用
$urlRouterProvider.otherwise('/');的默认设置和一个与该url匹配的状态。现在如果你去http://localhost:3000/dashboard那么路由器不知道该怎么做
标签: javascript ruby-on-rails angularjs