2016-04-26 85 views
0

在特定頁面上注入元標記我有一個應用程序,我想注入一個smartBanner元標記,但只在某些頁面上。使用指令

在我的索引頁,我有:

<!DOCTYPE html> 
<html ng-app="ngBoilerplate" ng-controller="AppCtrl"> 
    <head> 
    <title ng-bind="pageTitle"></title> 
<!-- add smart banner to select pages through smartBanner directive --> 

<smart-banner></smart-banner> 


</head> 
    <body> 
    <ui-view></ui-view> 
    </body> 
</html> 

我有一個指令:

angular.module('boh.components.smartBanner', []) 

.directive('smartBanner', function(){ 
    return { 
     restrict: "E", 
     template: '<meta name="apple-itunes-app" content="app-id=1080200000"></meta>', 
     replace: true 
    } ; 
}); 

我的問題是,我只是通過注入指令到我的其他頁面控制器調用指令?

回答

0

我發現處理這個問題的最好方法是通過應用程序的PHP包裝工作。

我結束了這樣的事情:

<?php 
    $urls = array("/app/explore", "/app/dashboard", "app/members", "/app/account-settings", "/app/jobs"); 
     foreach ($urls as $key => $value) { 
     if($_SERVER['REQUEST_URI'] === $value) { ?> 
      <meta name="apple-itunes-app" content="app-id=########"> 
     <?php } 
     } 
    ?>