AngularJS 错误 current.$$route 未定义
AngularJS error current.$$route is undefined
我了解了angularjs。但是我在设置标题时发现了错误。
我的应用.js
'use strict';
var serviceBase = 'http://www.yiiangular.dev/'
var spaApp = angular.module('spaApp', [
'ngRoute',
'ModuleTesting',
]);
var spaApp_test = angular.module('ModuleTesting', ['ngRoute']);
spaApp.config(['$routeProvider', function($routeProvider, $locationProvider) {
$routeProvider.otherwise({
redirectTo: '/test/index'
});
}])
.run(['$rootScope', function ($rootScope) {
$rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
$rootScope.title = current.$$route.title;
});
}]);
这个错误像
错误:当前.$$route 未定义
和我的控制器:
'use strict';
spaApp_test.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/test/action1', {
templateUrl: 'views/book/index.html',
title: 'Action 1',
controller: 'action1'
})
.when('/test/action2', {
templateUrl: 'views/book/index.html',
title: 'Action 2',
controller: 'action2'
})
.when('/test/index', {
templateUrl: 'views/book/index.html',
title: 'Action Index',
controller: 'index'
})
.otherwise({
redirectTo: '/test/index'
});
}])
.controller('index', ['$scope', '$http', function($scope,$http) {
$scope.message = 'Index Page';
}])
.controller('action1', ['$scope', '$http', function($scope,$http) {
$scope.message = 'Action I Page';
}])
.controller('action2', ['$scope', '$http', function($scope,$http) {
$scope.message = 'Action II Page';
}]);
如何解决此错误?
我已经在我的<html>
标签中设置了ng-app="spaApp"。
我错过了什么代码?哦,是的,我使用AngularJS v1.4.7
谢谢
为什么在 <head>
标签中设置它?这意味着 angular 只会在该标签之间运行。如果您希望整个应用程序启用角度,则需要在<html>
标签上。
我在 1.4.2 上,所以我们应该很接近。
$$route看起来像是一个内部角度项目。如果您注销$routeChangeSuccess中的当前,您将看到否则路径 $$route 不存在。在这种情况下,有效的方法是只需在您的$routeChangeSuccess中使用current.title,您就会成为黄金。
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- AngularJS 错误 current.$$route 未定义
- Meteor:Session.set,在Router.route()中,在“客户端”页面中使用时是未定义的
- Angular$route服务没有;t被按时注入到控制器中——最初在页面加载时未定义,但后来一切都像符咒一样工作
- 在Route类中未定义this.controller
- 聚合物将app-route的数据传递给未定义的自定义元素