一尘不染

角度修改元标记

angularjs

我有一个meta标签(苹果智能横幅),我想即时修改参数。但是,目前无法正常工作:

我假设在创建头部之前调用了ng-init?如果可以,我可以通过加载方法修改meta吗?

这是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>

部分:

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

控制器:

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

          $scope.paramRId = 'test';


       };

阅读 219

收藏
2020-07-04

共1个答案

一尘不染

尝试服务和指令

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;
    };
});
2020-07-04