我使用ng-view来包含AngularJS的部分视图,我想根据包含的视图来更新页面标题和h1标题标签。这些超出了局部视图控制器的范围,所以我不知道如何将它们绑定到控制器中的数据集。
如果是ASP.NET MVC。我已经搜索了共享服务,事件等,但仍然无法正常工作。任何方式来修改我的例子,所以它的作品将不胜感激。
我的HTML:
<html data-ng-app="myModule"><head><!-- include js files --><title><!-- should changed when ng-view changes --></title></head><body><h1><!-- should changed when ng-view changes --></h1><div data-ng-view></div></body></html>我的JavaScript:var myModule = angular.module('myModule', []);myModule.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/test1', {templateUrl: 'test1.html', controller: Test1Ctrl}). when('/test2', {templateUrl: 'test2.html', controller: Test2Ctrl}). otherwise({redirectTo: '/test1'});}]);function Test1Ctrl($scope, $http) { $scope.header = "Test 1"; /* ^ how can I put this in title and h1 */ }function Test2Ctrl($scope, $http) { $scope.header = "Test 2"; }相似问题