【问题标题】:Angular 2 - internationalisation - Include Custom Meta Data Information?Angular 2 - 国际化 - 包括自定义元数据信息?
【发布时间】:2023-03-15 23:01:01
【问题描述】:
  • 是否可以在Angular2中拥有元数据信息 默认工具(i18n)?

例子:

<key id="1">
<value>login</value>
<description>This is used in login screen</description>
<length>10</length>
<height>20</height>
</key>
  • 还有其他支持元数据信息的 Angular 2 国际化工具吗?

【问题讨论】:

    标签: angular internationalization


    【解决方案1】:

    没有实现 Angular 内部 i18n 工具来操作元标记,但它计划用于 Angular Universal according to ocombe

    您可以使用 Angular 4 中包含的 Meta service 操作元标记并编写自己的方法。

    Meta 添加到您的app.component.ts

    import { Meta } from '@angular/platform-browser';
    

    Meta 添加到您的构造函数中:

    constructor(private meta: Meta) {
    

    添加元标记:

    this.meta.addTag({ name: 'test', content: 'test1' });
    // or many at once:
    this.meta.addTags([
      { name: 'test', content: 'test2' },
      { name: 'test', content: 'test 3' },
      { name: 'testX', content: 'test 4' },
      { name: 'testY', content: 'test 5' },
      ]);    
    

    获取元标记:

    // only gets the first occurrence if the attribute is used multiple times
    console.log('tag: ' + this.meta.getTag('name=test').content);
    
    // gets the outer html
    this.meta.getTags('name="test"').forEach(value => console.log('html:', value));
    // gets the content
    this.meta.getTags('name="test"').forEach(value => console.log('content: ' + value.content));
    // gets the object
    console.log('object: ', this.meta.getTags('name="test"'));
    

    更新元标记:

    // only updates the first occurrence!
    this.meta.updateTag({name: 'test', content: 'abc'});
    

    删除元标记:

    // only deletes the first occurrence
    this.meta.removeTag('name="test"');
    // does the same as above but takes an `HTMLTagElement`instead of an attribute selector
    this.meta.removeTagElement(this.meta.getTag('name=test'));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 2018-04-29
      • 1970-01-01
      相关资源
      最近更新 更多