Javascript 如何在文档头中使用特定于AngularJS控制器的范围值?
我试图在标题标签中使用范围值。这是具有我的控制器的body元素的外部。有办法做到这一点吗 这是我的HTML:Javascript 如何在文档头中使用特定于AngularJS控制器的范围值?,javascript,angularjs,controller,title,head,Javascript,Angularjs,Controller,Title,Head,我试图在标题标签中使用范围值。这是具有我的控制器的body元素的外部。有办法做到这一点吗 这是我的HTML: <!DOCTYPE html> <html ng-app="soCLean"> <head> <title>{{locale}} {{type}} {{service}}</title> </head> <body ng-controller="soCleanLandin
<!DOCTYPE html>
<html ng-app="soCLean">
<head>
<title>{{locale}} {{type}} {{service}}</title>
</head>
<body ng-controller="soCleanLandingPage">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<script>
var soClean = angular.module('soClean', []);
soClean.controller('soCleanLandingPage', ['$scope', function ($scope) {
$scope.locale = 'vancouver';
$scope.type = 'residential';
$scope.service = 'pressure washing';
$scope.serviceSingle = 'pressure wash';
}]);
</script>
</body>
</html>
{{locale}{{type}{{{service}}
var soClean=角度模块('soClean',[]);
控制器('soCleanLandingPage',['$scope',函数($scope){
$scope.locale='温哥华';
$scope.type=‘住宅’;
$scope.service=‘压力清洗’;
$scope.serviceSingle=‘压力清洗’;
}]);
感谢您的帮助。您可以使用$rootScope:
app.run(function($rootScope){
$rootScope.locale = "en";
$rootScope.type = "something";
$rootScope.service = "another";
});
您还可以使用一个奇特的指令:
app.directive('title', function(){
return {
restrict: 'E',
scope:{},
template: "{{locale}} {{type}} {{service}}",
link: function(scope){
scope.locale = "en";
scope.type = "something";
scope.service = "another";
}
}
});
选中此选项:您可以使用$rootScope:
app.run(function($rootScope){
$rootScope.locale = "en";
$rootScope.type = "something";
$rootScope.service = "another";
});
您还可以使用一个奇特的指令:
app.directive('title', function(){
return {
restrict: 'E',
scope:{},
template: "{{locale}} {{type}} {{service}}",
link: function(scope){
scope.locale = "en";
scope.type = "something";
scope.service = "another";
}
}
});
选中此选项:您可以使用$rootScope:
app.run(function($rootScope){
$rootScope.locale = "en";
$rootScope.type = "something";
$rootScope.service = "another";
});
您还可以使用一个奇特的指令:
app.directive('title', function(){
return {
restrict: 'E',
scope:{},
template: "{{locale}} {{type}} {{service}}",
link: function(scope){
scope.locale = "en";
scope.type = "something";
scope.service = "another";
}
}
});
选中此选项:您可以使用$rootScope:
app.run(function($rootScope){
$rootScope.locale = "en";
$rootScope.type = "something";
$rootScope.service = "another";
});
您还可以使用一个奇特的指令:
app.directive('title', function(){
return {
restrict: 'E',
scope:{},
template: "{{locale}} {{type}} {{service}}",
link: function(scope){
scope.locale = "en";
scope.type = "something";
scope.service = "another";
}
}
});
选中此选项:只需将ng控制器移动到html元素 (您可以在调试器中看到head中的值)
{{locale}{{type}{{{service}}
{{locale}}
{{type}}
{{service}}
{{serviceSingle}}
var soClean=角度模块('soClean',[]);
控制器('soCleanLandingPage',['$scope',函数($scope){
$scope.locale='温哥华';
$scope.type=‘住宅’;
$scope.service=‘压力清洗’;
$scope.serviceSingle=‘压力清洗’;
}]);
只需将ng控制器移动到html元素
(您可以在调试器中看到head中的值)
{{locale}{{type}{{{service}}
{{locale}}
{{type}}
{{service}}
{{serviceSingle}}
var soClean=角度模块('soClean',[]);
控制器('soCleanLandingPage',['$scope',函数($scope){
$scope.locale='温哥华';
$scope.type=‘住宅’;
$scope.service=‘压力清洗’;
$scope.serviceSingle=‘压力清洗’;
}]);
只需将ng控制器移动到html元素
(您可以在调试器中看到head中的值)
{{locale}{{type}{{{service}}
{{locale}}
{{type}}
{{service}}
{{serviceSingle}}
var soClean=角度模块('soClean',[]);
控制器('soCleanLandingPage',['$scope',函数($scope){
$scope.locale='温哥华';
$scope.type=‘住宅’;
$scope.service=‘压力清洗’;
$scope.serviceSingle=‘压力清洗’;
}]);
只需将ng控制器移动到html元素
(您可以在调试器中看到head中的值)
{{locale}{{type}{{{service}}
{{locale}}
{{type}}
{{service}}
{{serviceSingle}}
var soClean=角度模块('soClean',[]);
控制器('soCleanLandingPage',['$scope',函数($scope){
$scope.locale='温哥华';
$scope.type=‘住宅’;
$scope.service=‘压力清洗’;
$scope.serviceSingle=‘压力清洗’;
}]);
将ng controller=“soCleanLandingPage”放在页眉上有用吗?布赖恩,我没有试过,但想知道是否可以在同一页上有两个同名的控制器。只试过这个。它只是使用您已经注册的控制器。也就是说,对于您的场景,Craig已经提供的答案可能是一个更好的解决方案。将ng controller=“soCleanLandingPage”放在头部是否有效?Brian,我没有尝试过,但想知道是否可以在同一页面上有两个同名的控制器。只是尝试了这个。它只是使用您已经注册的控制器。也就是说,对于您的场景,Craig已经提供的答案可能是一个更好的解决方案。将ng controller=“soCleanLandingPage”放在头部是否有效?Brian,我没有尝试过,但想知道是否可以在同一页面上有两个同名的控制器。只是尝试了这个。它只是使用您已经注册的控制器。也就是说,对于您的场景,Craig已经提供的答案可能是一个更好的解决方案。将ng controller=“soCleanLandingPage”放在头部是否有效?Brian,我没有尝试过,但想知道是否可以在同一页面上有两个同名的控制器。只是尝试了这个。它只是使用您已经注册的控制器。也就是说,对于您的场景,Craig已经提供的答案可能是更好的解决方案。谢谢Craig,我想知道我是否可以这样做,但认为控制器需要嵌套在应用程序中。谢谢Craig,我想知道我是否可以这样做,但认为控制器需要嵌套在应用程序中。谢谢Craig,我想知道我是否能做到这一点,但我认为控制器需要嵌套在应用程序中。谢谢Craig,我想知道我是否能做到这一点,但我认为控制器不能