Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于视图AngularJS错误更改文本_Angularjs - Fatal编程技术网

基于视图AngularJS错误更改文本

基于视图AngularJS错误更改文本,angularjs,Angularjs,我试图弄清楚为什么我使用的脚本会出错。我在我的应用程序上有两个页面,我想在切换视图时更改一些标题文本。它以其当前的形式工作,但我一直收到一个控制台错误,我想修复它。代码如下: .run(['$rootScope', function($rootScope) { $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { $rootScope.title = current.$$ro

我试图弄清楚为什么我使用的脚本会出错。我在我的应用程序上有两个页面,我想在切换视图时更改一些标题文本。它以其当前的形式工作,但我一直收到一个控制台错误,我想修复它。代码如下:

.run(['$rootScope', function($rootScope) {
    $rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
        $rootScope.title = current.$$route.title;
    });
然后在我的HTML中:

<h1 class="section-intro" ng-bind="title"></h1>

我很困惑,因为脚本可以正常工作,但是当我切换回第四个和第四个时会抛出错误。

这将是一个简单的修复,只需使用
current.title
而不是private
$$route
对象<代码>当前路由将继承
标题

app.run(['$rootScope', function($rootScope) {
    $rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
        $rootScope.title = current.title;
    });
}]);

在您看来,它应该是
$root.title
而不仅仅是
title
。另外,在当前和路由之间加倍
$
<代码>$$是为私有变量保留的。如何定义标题?
   $rootScope.title = current.$$route.title;
app.run(['$rootScope', function($rootScope) {
    $rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
        $rootScope.title = current.title;
    });
}]);