2016-06-12 38 views
0

元标签是否有任何方式可以被Angular-Ui-Router控制或包含在Angular模板中?Meteor + Angular-UI路由器中的Meta标签(即<title>)

在Meteor Angular中,您的应用不能像这样包装:<html ng-app="app">,它至少需要<body ng-app="app">才能工作 - Meteor会处理所有CSS和JS依赖关系。因此,您的Angular应用程序无法访问<head>(如$rootScope)。

无角UI的路由器,你可以简单地添加(partyDetails.html):

<head> 
    <title>Details of party {{}}</title> 
</head> 

在你的模板,不与UI的路由器下工作,我得到:

Error: Cannot find module './partyDetails.html' 
Error: [$injector:modulerr] Failed to instantiate module app due to: 
[$injector:nomod] Module 'app' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 

删除<head>标签后就可以了。

我需要在我的网站上有动态标签(如提到的<title></title>,但不仅仅是!) - 它实际上可行吗?

回答

0

我设法使用yasinuslu:blaze-meta。您的组件控制器:

import angular from 'angular'; 
import angularMeteor from 'angular-meteor'; 
import uiRouter from 'angular-ui-router'; 
import { Meteor } from 'meteor/meteor'; 
import { Meta } from 'meteor/yasinuslu:blaze-meta'; 

//.. 

class PartyDetailsCtrl { 
    constructor($stateParams, $scope) { 
     'ngInject'; 

     //.. 

     Meta.config({ 
      options: { 
       title: "Default Title", 
       suffix: "Socially", 
       separator: " — " 
      } 
     }) 

     Meta.set({ 
      name: 'name', 
      property: 'description', 
      content: 'Meta description' 
     }); 

     Meta.setTitle("Party Details"); 

    } 
    //.. 
} 
//.. 

我相信Meta.config({})可以被放置在你的应用程序的.run块。希望有所帮助!