gpt4 book ai didi

javascript - 如何在文档头中使用 AngularJS Controller 特定的范围值?

转载 作者:行者123 更新时间:2023-11-28 19:59:50 25 4
gpt4 key购买 nike

我正在尝试在我的标题标签中使用我的范围值。这是具有我的 Controller 的主体元素的外部。有办法做到这一点吗?

这是我的 HTML:

<!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>

感谢您的帮助。

最佳答案

只需将 ng-controller 移至 html 元素即可。

http://plnkr.co/edit/xImv48BvoW2Y9Ibb9JTq?p=preview(可以在调试器中看到head中的值)

<!DOCTYPE html>
<html ng-app="soClean" ng-controller="soCleanLandingPage">
<head>
<title>{{locale}} {{type}} {{service}}</title>
</head>
<body >
<div>
<p>{{locale}}</p>
<p>{{type}}</p>
<p>{{service}}</p>
<p>{{serviceSingle}}</p>
</div>
<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>

关于javascript - 如何在文档头中使用 AngularJS Controller 特定的范围值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21866128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com