Lautaro Lautaro - 15 days ago 5
TypeScript Question

Setting the title with Angular

I'm trying to work with an Angular app I don't know so much about. It uses TypeScript Angular 1.5. I need to be able to change the page's title. This is what I have to work with. I'm not sure how it works without ng-app specified, but it works.

Is there a way to set the title in the head dynamically? Or would I need to change the ng-controller attr to the html element? If so how could it affect the system?

<!DOCTYPE html>

<html lang="sv">

<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>MySajt</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/styles.css" rel="stylesheet">
</head>

<body ng-controller="AppController as vm" ng-class="{ 'v-dolj-overflow': vm.togglaScroll }">

<my-header></my-header>

<div class="v--header-offset" ui-view></div>

<script src="js/app.js"></script>
<script src="js/angular-locale_sv.js"></script>

</body>

</html>

Answer

You should be able to accomplish this with document.title regardless of where the controller lives https://developer.mozilla.org/en-US/docs/Web/API/Document/title