我正在尝试从链接在另一个JS文件中的其他控制器获取变量。我想显示从其他控制器分配的页面标题。如果我路由到extract.html,则必须在html标题中显示“提取首页”文本,我在extract.js中声明了此变量
请帮助我,在此先感谢
Main.html
<html lang="en" ng-app="routing" ng-controller="landingCtrl">
<title>{{page_location_text}} - Noble Institute</title>
<body>
<div ng-view></div>
</body>
</html>
<script>
var routingApp = angular.module("routing", ["ngRoute","extract"]);
routingApp.controller("landingCtrl",function($scope){
$scope.page_location_text = $scope.page_location;
});
routingApp.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "index.html"
})
.when("/extract", {
templateUrl : "extract.html",
controller : "extractCtrl"
});
});
</script>
用于Extract.html的Extract.js
<script>
var app = angular.module('extract', ['angularUtils.directives.dirPagination',"ngSanitize", "ngCsv"]);
app.controller('extractCtrl',function($scope, $http, $routeParams, filterFilter){
$scope.page_location = "Extract Home";
});
</script>
您可以使用路线设置标题,并将标题放在html上,例如:
<title ng-bind="title">myApp</title>
并在您的路由配置中设置标题,例如:
.when("/extract", {
title : 'Extract Home',
templateUrl : "extract.html",
controller : "extractCtrl"
});
并为您的角度应用程序设置运行方法:
app.run(['$rootScope', '$route', function($rootScope, $route) {
$rootScope.$on('$routeChangeSuccess', function() {
document.title = $route.current.title;
});
}]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句