小编Lak*_*ngh的帖子

在角度模板中使用样式标记中的变量?

我正在开发angular 5应用程序,我需要在模板中的样式标记中应用动态css.我尝试了一些解决方案,但它们没有用.

app.component.ts

customCss : any;

constructor(){}

ngOnInit(){
   this.customCss['color'] = "red";
}
Run Code Online (Sandbox Code Playgroud)

app.component.html

<div>
   <span class="custom_css">This is angular 5 application</span>
</div>

<style>
   .custom_css{
      color: {{customCss.color}};
   }
</style>
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中检查custom_css类时,它显示的样式

.custom_css{
   color: {{customCss.color}};
}
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

html javascript css angular angular5

11
推荐指数
3
解决办法
6608
查看次数

如何在angular2中的嵌套表单字段中获取和设置值?

我正在开发angular2应用程序并使用角度反应形式.如何获得最内层元素的值并设置其值.

form : FormGroup;

constructor(private formBuilder: FormBuilder)
{
   this.form = formBuilder.group({
      'home_cleaning' : [{
           cities : FormBuilder.array([])
       }]
   });
}

setValue()
{
    let cities_array = [1,2,3,4];
    this.form.controls['home_cleaning']['cities'].setValue(cities_array);
}

getValue()
{
   console.log(this.form.controls['home_cleaning']['cities'].value);
}
Run Code Online (Sandbox Code Playgroud)

在控制台中获取错误:无法读取undefined的属性'setValue/value'.

angular

8
推荐指数
3
解决办法
7547
查看次数

如何在angular2中以反应形式存储多个复选框值?

我正在处理angular2应用程序,并在表单字段中存储多个复选框的值时遇到问题.

输入脚本

form : FormGroup;
cities = ["Mohali", "Chandigarh", "Ludhiana", "Amritsar"];
zip_codes = ["282001", "456123", "123456", "140412"];

constructor(private formBuilder : FormBuilder)
{
    this.form = this.formBuilder.group({
       cities   : this.formBuilder.array(["Mohali", "Amritsar"]),
       zip_codes : this.formBuilder.array(["456123"])
    });
}
Run Code Online (Sandbox Code Playgroud)

HTML

<div *ngFor="let city of cities">
    <input type="checkbox" formControlName="cities" value="city">
    <span>{{city}}</span>
</div>

<div *ngFor="let zipCode of zip_codes">
    <inbput type="checkbox" formControlName="zip_codes" value="zipCode">
     <span>{{zipCode}}</span>
</div>
Run Code Online (Sandbox Code Playgroud)

我想在表单字段中存储已检查的城市和zip_codes,当我在表单字段中有默认值时,将自动检查数组中的值.

angular2-forms angular

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

当我更新“@angular-devkit/build-angular”时,style-loader 停止工作

我在 angular8 工作并面临一个问题,

为了动态加载我的样式,我使用了波纹管代码并且它运行良好,但是当我将包更新"@angular-deficit/build-angular": "^0. 800.0"为 时"@angular-deficit/build-angular": "^0. 803.21",它停止工作。该应用程序运行良好,终端和浏览器控制台中没有错误,但应用程序上未实现样式。

declare function require(name: string): any;
 ngOnInit() {
    require('style-loader!./file-path');
}
Run Code Online (Sandbox Code Playgroud)

包.json

{
"name": "latest-frontend-theme",
"version": "0.0.0",
"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "bundle-report": "webpack-bundle-analyzer dist/stats.json"
},
"private": true,
"dependencies": {
    "@agm/core": "^1.1.0",
    "@angular/animations": "^8.2.14",
    "@angular/cdk": "^8.2.3",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@ngx-loading-bar/core": "^4.2.0",
    "@ngx-loading-bar/router": …
Run Code Online (Sandbox Code Playgroud)

javascript webpack-style-loader angular angular6 angular8

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

Google 翻译 API 中出现“文本片段过多”错误

我正在 Angular-12 工作。在我们的系统中,我们使用“Google Translate”API。

因此,当我们尝试批量翻译字符串时,API 会返回错误

 {
  "error": {
    "code": 400,
    "message": "Too many text segments",
    "errors": [
      {
        "message": "Too many text segments",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我们在 API 中发送的数据类型,

我们正在使用的 API https://translation.googleapis.com/language/translate/v2?key=Alza......

 {
        "source":"en",
        "target":"es",
        "q":["string1", "string1",......]
    }
Run Code Online (Sandbox Code Playgroud)

任何形式的帮助都是值得的,谢谢。

javascript google-translate google-translation-api angular12

3
推荐指数
1
解决办法
1536
查看次数

在角度材质2中的md-select中设置默认选项

我试图设置md-selectangular-material2 的默认选项,但无济于事.

form2.component.ts:

export class Form2Component implements OnInit {
    frequency = [
                {"title" : "One Time",         "description" : "", "discount" : {"value" : 0,  "type" : "value"} },
                {"title" : "Weekly",           "description" : "", "discount" : {"value" : 20, "type" : "percent"} },
                {"title" : "Every other Week", "description" : "", "discount" : {"value" : 15, "type" : "percent"} },
                {"title" : "Monthly",          "description" : "", "discount" : {"value" : 10, "type" : "percent"} }
            ]
    constructor(){}
    ngOnInit(){} …
Run Code Online (Sandbox Code Playgroud)

angular-material2 angular

2
推荐指数
1
解决办法
3951
查看次数