Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular modify meta tag

Tags:

angularjs

I have a meta tag (apple smart banner) and I want to modify the argument on the fly. However it is currently not working:

I assume the ng-init is called before the head is created? If so, I can modify the meta through a load method?

here is the html:

<!doctype html>
<html lang="en" ng-app="myApp" class="passWindowDimensions">
<head>
    <meta charset="utf-8">
    <title>XXXXXX</title>
    <link rel="stylesheet" href="css/app.css"/>
    <link rel="stylesheet" href="css/bootstrap.css"/>

    <meta name="apple-itunes-app" content="app-id=XXXXXXX, app-argument = {{paramRId}}">

    <!--Let search engines know we are a single page ajax app-->
    <meta name="fragment" content="!">

    <script src="js/JQuery.js"></script>
    <script src="js/searchFunctions.js"></script>


</head>

Partial:

<div data-ng-init="loadMe()" div class="col-md-12 passWindowDimensions">

Controller:

/**
         * Loading sequence. Loads the results
         */
        $scope.loadMe = function(){

          $scope.paramRId = 'test';


       };
like image 861
William Falcon Avatar asked Dec 27 '13 20:12

William Falcon


People also ask

What is meta tag in angular?

The Angular Meta Service makes it easier to set different meta tags to different pages. It provides methods such as addTag() , addTags() , getTag() , getTags() , updateTag() , removeTag() , removeTagElement() etc. We can use them to manipulate meta tags. Let us find out how to use Meta service using an example.

What is the tag used for showing route dynamically in angular?

Meta Tags in Route Add the Meta Tags property in route data. We can use the Route data to pass the static data or dynamic data to routed components.


1 Answers

Try a service and a directive

http://jsfiddle.net/VnXYB/

module.factory("smartBanner", function() {
    return {
        appId: "",
        appArgument: ""
    }    
});
module.directive("smartBanner",function(smartBanner){
    return {
        restrict: "E",
        template: '<meta name="apple-itunes-app" content="app-id={{smartbanner.appId}}, app-argument = {{smartbanner.appArgument}}"></meta>',
        replace: true,
        link: function(scope) {
            scope.smartbanner = smartBanner
        }
    } 

});
module.controller("TestCtrl", function($scope,smartBanner){
    $scope.update = function() {
        smartBanner.appId=$scope.appId;
        smartBanner.appArgument=$scope.appArgument;
    };
});
like image 173
kfis Avatar answered Sep 28 '22 02:09

kfis