[英]Access variables in routing page controller declared in different controller in angularjs
我试图从另一个链接的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;
});
}]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.