以下是我的index.html
页面:
<title>Mytitle<title>
<meta name="keywords" content="abc,xyz"/>
<meta name="description" content="cde,fgh"/>
我想要在 signup.html
页面中使用不同的标题、关键字和说明:
(index.html
页面下的signup.html
页面渲染器)
<title>Signup Title<title>
<meta name="keywords" content="signup, free"/>
<meta name="description" content="do signup for free"/>
最佳答案
对于您的情况,您可以将应用程序和 Controller 添加到 HTML 标记(例如)并使用数据绑定(bind),如下所示:
<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
从子 Controller 控制此作用域变量:
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";
}
关于javascript - 如何在 AngularJs 中更新不同页面上的元标记和标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44604195/