William Falcon
William Falcon

Reputation: 9813

Angular modify meta tag

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';


       };

Upvotes: 9

Views: 11688

Answers (3)

user3215547
user3215547

Reputation: 49

The angular meta module manages your title tags and meta descriptions. It uses the same API as the $routeProvider, so it's super easy to configure.

https://github.com/monyiliev/angular-meta

Upvotes: 4

kfis
kfis

Reputation: 4729

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;
    };
});

Upvotes: 4

Joe
Joe

Reputation: 2596

Which section of the page is your controller responsible for? I can't test this in a fiddle because the head tag is off limits, but it seems to me like you may just need to change

$scope.paramRId = 'test';

to

$scope.$root.paramRId = 'test';

Upvotes: 4

Related Questions