国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

angular.js - How do you deal with the page title of a single-page application?
漂亮男人
漂亮男人 2017-05-15 16:57:53
0
3
644

More and more websites are now using SPA technology. The front-end routes itself and partially refreshes the page. The single-page application is also a webapp. Compared with the previous one, the entire site was an independent page, and each page was There is a separate html to write <title>你是猴子派來的逗比么</title>, so how do you deal with the page title problem in single-page applications

漂亮男人
漂亮男人

reply all(3)
曾經(jīng)蠟筆沒有小新

I saw an answer on stackoverflow, he implemented it like this

  • First add a global controller to the html:

    <html ng-app="plunker" ng-controller="MainCtrl">
  • Then I wrote a factory:

    app.factory('Page', function(){
      var title = 'default';
      return {
        title: function() { return title; },
        setTitle: function(newTitle) { title = newTitle; }
      };
    });
  • Then index.html主頁面中就可以通過<h1>{{ Page.title() }}</h1>get the page title

  • It is very simple to set the title of the specific corresponding page, just inject this Page into your controller

    function Page2Ctrl($scope, Page) {
      Page.setTitle('title1');
    }

Here is the specific implementation: http://plnkr.co/edit/0e7T6l?p=info

給我你的懷抱

js 中使用 document.title = '...' 就能修改 title Got it

If you want better results, you can use the H5 的新特性 history.pushState(state, title, url) ,這個方法不但能修改 title ,還能同時修改 url address and record this information into the history stack. When the user uses the browser's back button, they will get a better experience.

習慣沉默
<title>{{mainAppCtrl.title}}</title>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template