對於你的情況您可以將應用程序和控制器添加到HTML標記(例如),並使用像這樣的數據綁定:
<html ng-app="yourApp" ng-contoller="YourController">
<head>
<title>{{title}}<title>
<meta name="keywords" content="{{keywordsContent}}"/>
<meta name="description" content="{{descriptionContent}}"/>
</head>
...
</html>
而在你YourController
:
angular
.module('yourApp', [])
.controller('YourController', ['$scope', YourController]);
function YourController($scope) {
$scope.title = "Mytitle";
$scope.keywordsContent = "abc,xyz";
$scope.descriptionContent = "cde,fgh";
}
,並且可以使用$scope.$parent
控制從子控制器此範圍內的變量:
angular
.module('yourApp', [])
.controller('ChildController', ['$scope', ChildController]);
function ChildController($scope) {
$scope.$parent.title = "Changed Title";
$scope.$parent.keywordsContent = "Changed Keywords";
$scope.$parent.descriptionContent = "Changed Description";
}
你檢查這[何燦我更新的元-tags-in-angularjs](https://stackoverflow.com/questions/16119398/how-can-i-update-meta-tags-in-angularjs?noredirect=1&lq=1)? –
和[Angular Dynamic meta tags in head](https://stackoverflow.com/a/32152701/3623027).. –
可能的重複[如何更新AngularJS中的元標記?](https:// stackoverflow。 com/questions/16119398/how-can-i-update-meta-tags-in-angularjs) –