angularjs - 如何在 AngularJs 中使用 UI-Route 在每个页面中设置动态元数据
问题描述
我正在开发一个在 AngularJs 中构建的应用程序,但我在动态设置元标题、名称、描述方面遇到了一些问题。我试过“ui.router.metatags”,但问题是当我在任何浏览器中查看源代码时,元标题、名称、描述都没有显示。它只显示为 {{meta.title}} 而不是注入的实际数据。
这是我的代码:
$stateProvider
.state('home', {
url: "/",
metaTags: {
title: 'title1',
description: 'description',
keywords: 'keyword1,keyword2,...',
properties: {
'og:title': 'title1'
}
},
views : {
"" : {
templateUrl:"/home/home.html",
controller: 'homeCtrl',
controllerAs:'vm',
}
},
resolve: {
loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {
return $ocLazyLoad.load('home'); // Resolve promise and load before view
}]
}
})
这是索引文件代码:
<title ng-bind="MetaTags.title">{{MetaTags.title}}</title>
<meta name="description" content="{{MetaTags.description}}">
<meta name="keywords" content="{{MetaTags.keywords}}">
解决方案
推荐阅读
- numpy - np.array() 如何在内部工作?
- elasticsearch - Elasticsearch - 从不在服务器 LAN 上的设备收集日志
- javascript - style.marginLeft 函数在 JavaScript 中不起作用
- kubernetes - Slice in helm 未找到匹配项
- javascript - 作为对象中的值附加到数组
- javascript - 如何在 puppeteer/playwright 中获取 pageXOffset 和 pageYOffset
- python - python中对自己进行评估的关键字
- sql - 我如何找到上个月当日销售和上个月当前周销售?
- angular - 在 mat-select 中获取选定的选项(多个)
- python - 为什么我仍然可以将记录导入到具有复合索引的表中?