我需要帮助完成项目。我在使用angularjs将标记加载到HTML HEAD时遇到问题。AngularJS服务API。共享链接时不要加载标题标签
我相信的问题是,当我分享一个链接在WhatsApp,Facebook等窃贼,不加载AngularJS,因此不加载变量的数据,因此只显示“源代码”。
正确: enter image description here
错误: enter image description here
版本:AngularJS V1.6.1
代码的html:
<!DOCTYPE html>
<html ng-app="ecApp" ng-controller="ecCtlr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=0" />
<meta name="fragment" content="!">
<title>{{produto.nome}}</title>
<meta name="description" content="{{produto.texto_descricao}}" />
<script src="angular.min.js"></script>
<script src="app.js"></script>
<script src="factory.js"></script>
<script>
var idLoja = 858;
function carregaScope() {
var scope = angular.element($('#ecCtlr')).scope();
scope.$apply(function() {
scope.buscaProduto(670706);
});
}
</script>
</head>
<body onLoad="carregaScope();" id="ecCtlr">
</body>
</html>
角APP:
var api = 'http://localhost/api/';
var app = angular.module('ecApp', []);
app.controller('ecCtlr', function ($scope, $sce, ECProdutos) {
$scope.buscaProduto = function(idProduto) {
ECProdutos.buscaProduto(idLoja, idProduto).then(function (produto) {
$scope.produto = produto;
$scope.produtoPai = produto;
});
};
});
厂:
angular.module("ecApp").factory("ECProdutos", function ($q, $http) {
var urlClass = 'ec/produto/';
return {
buscaProduto: function (idLoja, idProduto) {
var promessa = $q.defer();
$http.get(api + '' + urlClass + 'buscaProduto/' + idLoja + '/' + idProduto).then(
function (result) {
promessa.resolve(result.data);
}
);
return promessa.promise;
}
};
});
1)你的代码在哪里? 2)由于我们看不到你的代码,因为你在问题中提到了两个,所以我们不知道你是否使用了Angular1或者2 ...所以任何人都很难帮助你。 –
@HunterTurner编辑,谢谢 –