2017-06-17 25 views
2

以下是我index.html頁:如何在AngularJs的不同頁面上更新元標籤和標題?

<title>Mytitle<title> 
<meta name="keywords" content="abc,xyz"/> 
<meta name="description" content="cde,fgh"/> 

,我想在signup.html頁面不同的標題,關鍵字和描述:

signup.html頁rendererd下index.html頁)

<title>Signup Title<title> 
<meta name="keywords" content="signup, free"/> 
<meta name="description" content="do signup for free"/> 
+0

你檢查這[何燦我更新的元-tags-in-angularjs](https://stackoverflow.com/questions/16119398/how-can-i-update-meta-tags-in-angularjs?noredirect=1&lq=1)? –

+0

和[Angular Dynamic meta tags in head](https://stackoverflow.com/a/32152701/3623027).. –

+0

可能的重複[如何更新AngularJS中的元標記?](https:// stackoverflow。 com/questions/16119398/how-can-i-update-meta-tags-in-angularjs) –

回答

0

對於你的情況您可以將應用程序和控制器添加到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"; 
} 
+0

嗨@商業自殺,非常感謝您的迴應。但如果我查看頁面源,我不想在頁面源中使用角度表達式{{title}}。讓我知道是否有其他方式。 –

+0

@SGRDalal,我不確定在angularjs中存在任何其他方式。但我認爲你可以通過獲取元素和更改屬性內容,通過純JavaScript或jQuery來實現。你可以嗎? –

相關問題