标签: angular6

Angular 6 SiteMap.xml - 最好的方法是什么

我需要包含在我的项目 sitemap.xml 中。

我知道我需要把它放在哪里。

"apps": [
{
 [...]
  "assets": [
    "assets",
    "favicon.ico",
    "sitemap.xml",
    "robots.txt"
  ],
 [...]
}
]
Run Code Online (Sandbox Code Playgroud)

但不确定如何生成它。我有很多动态的 URL

最好的方法是什么?

angular angular5 angular6

5
推荐指数
1
解决办法
9972
查看次数

将变量从 .ts 导入 .scss angular

我正在开发一个角度组件,我想从我的 ts 文件中导入我的 scss 文件变量(例如颜色),并且我遇到了一些问题。我看过一些 node-sass 和 webpack 的例子,但对我来说不是很清楚。谢谢

javascript sass typescript angular angular6

5
推荐指数
2
解决办法
7931
查看次数

仅将角度材料主题应用于特定组件

是否可以将 angular material 内置主题仅应用于特定组件?

我做了:

@import "~@angular/material/prebuilt-themes/indigo-pink.css";
Run Code Online (Sandbox Code Playgroud)

在我的 component.scss 文件之一中,并将其作为 component.ts 文件中的 styleUrl 引用。但是这些样式不适用于我的 angular material paginator。

这是分页器的样子

在此处输入图片说明

如图所示,样式不适用。

这是否与我将它们导入到组件特定的 scss 文件中而不是在 angular.json 中导入的事实有关?

angular-material angular angular6

5
推荐指数
1
解决办法
3290
查看次数

角度单选按钮的动态列表

我有一个不属于表单的单选按钮列表。我想根据一个值将其中一个设置为 true。

然后,当另一个人被点击时,除了被点击的那个之外,所有其他人都被设置为 false。

单选按钮列表是动态的,由 a ngFor,

我有类似的东西

<div *ngFor='let item of array;let i = index'>                    
   <input type="radio" [checked]=false (click)='radioChecked(item.id,i)' > <input type="text" value='{{item.name}}' >  <button type="button" >save</button>                    
 </div>  

ngOnInit() {  
  this.myService.getNumber(id).subscribe((data) =>{  
  //when the page loads, set one of radiobuttons to true
  //somehow get the id and set to true, no standard is, since dynamic list
  radioId.value = true;
  })
}

radioChecked(id, i){
  //turn all the others to false, except this one
}
Run Code Online (Sandbox Code Playgroud)

由于这不是表单并且没有标准行,所以我可以有一个 id,我该怎么做?我使用角度 6

谢谢

radio-button angular angular6

5
推荐指数
1
解决办法
5306
查看次数

Angular 一次在多个地方使用相同的 TemplateRef - 克隆 TemplateRef?

我正在尝试构建一个多选组件,它可以为每个选择选项元素采用一个模板。它主要工作,模板是从选项组件中的 ng-content 中抓取的,并显示在“选择弹出窗口”中。

选项显示正常

尝试在选择组件中显示所选选项时遇到问题。似乎模板一次只能在一个地方显示,因此当在“选择”中显示所选选项时,它将从POPOVER中删除。

选项显示错误

有什么办法可以克隆 TemplateRef 组件吗?我实际上并不介意模板的上下文是否更新,因为我目前没有使用它的任何内容,只是模板。

为了清楚起见,包括下面的一些代码片段,我认为这没关系。

用途somepage.component.html:

<my-select [(value)]="vals">
    <my-option *ngFor="let x of [1,2,3]" [value]="x">Option {{x}}</my-option>
</my-select>`
Run Code Online (Sandbox Code Playgroud)

我的选择.component.html

...
<ng-container [ngTemplateOutlet]="getSelectedOptionTemplate()"></ng-container>
...
Run Code Online (Sandbox Code Playgroud)

我的select.component.ts

getSelectedOptionTemplate(){
    // Some way to clone here could solve the issue?
    return this.getSelectedOption().template;
}
Run Code Online (Sandbox Code Playgroud)

my-select-overlay.component.html

...
<ng-container *ngFor="let opt of options;">
    <ng-container [ngTemplateOutlet]="getTemplate(opt)"></ng-container>
</ng-container>
...
Run Code Online (Sandbox Code Playgroud)

my-option.component.html

<ng-template>
    <ng-content></ng-content>
</ng-template>
Run Code Online (Sandbox Code Playgroud)

my-option.component.ts

...
@ViewChild(TemplateRef)
template: TemplateRef<any>;
...
Run Code Online (Sandbox Code Playgroud)

angular angular6

5
推荐指数
1
解决办法
295
查看次数

“IconDefinition”类型的参数不可分配给“IconDefinitionOrPack”类型的参数

我用角6角起动机 和fontawesome,随后这里就如何发安装到纳克。

在我的 .ts 看起来像这样:

import { library, dom } from '@fortawesome/fontawesome-svg-core';
import { faInstagram } from '@fortawesome/free-brands-svg-icons/faInstagram';
import { faLink } from '@fortawesome/free-solid-svg-icons/faLink';

public ngOnInit() {
    library.add(faInstagram);
    library.add(faLink);
    dom.watch();
}
Run Code Online (Sandbox Code Playgroud)

然后在 .html 中:

<fa-icon [icon]="['fab', 'instagram']"></fa-icon>
Run Code Online (Sandbox Code Playgroud)

除了免费品牌,它工作得很好@fortawesome/free-brands-svg-icons。在构建(npm start)时,它会Argument of type 'IconDefinition' is not assignable to parameter of type 'IconDefinitionOrPack'. 'IconDefinition' is not assignable to type 'IconPack'. signature is missing in type 'IconDefinition'.在 92% 的构建中产生错误/警告,但实际上构建似乎成功并且显示了 instagram 图标,但我很烦恼,因为代码下方出现了一条红线。

有人能弄清楚吗?

我的 package.json

"@fortawesome/angular-fontawesome": "^0.3.0",
"@fortawesome/fontawesome-svg-core": …
Run Code Online (Sandbox Code Playgroud)

font-awesome angular6

5
推荐指数
1
解决办法
1958
查看次数

在 ionic 4 中设置渐变背景

我只想为几页添加渐变背景,

登录页面.html

<ion-header>

</ion-header>

<ion-content padding class="bg-class">
   <p>lorem</p>
</ion-content>
Run Code Online (Sandbox Code Playgroud)

_login.page.css

.bg-class{
    background-image: linear-gradient(197deg, rgba(100,100,100,1) 0%, rgba(63,63,63,1) 13.5%, rgba(29,29,29,1) 33.33%, rgba(0,0,0,1) 100%) !important
}
Run Code Online (Sandbox Code Playgroud)

这不起作用,我能知道我哪里出错了吗?我还需要做些什么才能使这个工作正常进行。

ionic-framework angular ionic4 angular6

5
推荐指数
1
解决办法
1万
查看次数

如何将类注入服务 [Angular 6]

我们可以将一个类(不是服务)作为共享实用程序,它可以通过角度依赖注入注入到服务甚至组件中吗?

我的实用类

export class MyUtilClass{

  do(){
     // something
  }
}
Run Code Online (Sandbox Code Playgroud)

我的服务

export class MyService{
  constructor(private uitl:MyUtilClass){
    util.do();
  }
}
Run Code Online (Sandbox Code Playgroud)

typescript angular angular6

5
推荐指数
1
解决办法
1484
查看次数

Angular 6 Material - 等待 Mat Dialog 关闭

我有一个要完成的操作列表,如果设置了布尔值 promptRequired,我会显示一个对话框并根据它的值执行一些操作。

这里的问题是 for 循环并行运行并且所有操作同时执行,但我希望 for 循环同步运行并且循环必须等到对话框关闭。有解决办法吗?

async runActions() {
 for (const action of Actions) {
      if(action.promptRequired) {
      const dialogRef = this.promptDialog.open(PromptDialogComponent, {
        data: {action: action,
        },
      });
      // await dialogRef.afterClosed();
     }
    }

     const status =  await this.httpService.getRequest('runAction', action)
     // Do Some Action based on status
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

asynchronous async-await angular-material angular angular6

5
推荐指数
1
解决办法
6789
查看次数

Angular 6 - angular.json - 通过重命名复制资产

我正在尝试在 ng build 的资产副本期间重命名文件

这是我在angular.json:

        "outputPath": "dist",
        "assets": [
          ...,
          {
            "glob": "favicon-v1.png",
            "input": "src/client",
            "output": "/favicon.png"
          },
          ...,
        ],
Run Code Online (Sandbox Code Playgroud)

不是创建文件dist/favicon.png,ng build而是创建一个dist/favicon.png/favicon-v1.png.

它似乎拒绝重命名文件 - 它总是使用我想使用的名称创建一个文件夹,favicon.png然后将原始文件放入其中。

这是预期的行为吗?任何不是文件重命名解决办法等favicon-v1.png,以favicong.png在源头控制?

我在用:

    "@angular/cli": "^6.1.5"

    "@angular/animations": "^6.0.1",
    "@angular/common": "^6.0.1",
    "@angular/compiler": "^6.0.1",
    "@angular/core": "^6.0.1",
    "@angular/forms": "^6.0.1",
    "@angular/http": "^6.0.1",
    "@angular/platform-browser": "^6.0.1",
    "@angular/platform-browser-dynamic": "^6.0.1",
    "@angular/router": "^6.0.1",
    "@angular/upgrade": "^6.0.1",
Run Code Online (Sandbox Code Playgroud)

更新:类似的代码在 Angular 5 中与 angular-cli.json 一起工作正常。

angular ng-packagr angular6

5
推荐指数
1
解决办法
3745
查看次数