小编Cha*_*har的帖子

角度2中的十进制管道 - 仅逗号,无小数位

我目前使用这个管道 {{ product.productPrice | number:'.2-2' }}

结果是1,000,000.00,但我想删除.00 你怎么做?

numbers decimal angular2-pipe angular

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

Angular 2:可以将焦点放在一个事件中吗?

可以focusin并且focusout在一个事件中吗?那叫什么呢?如果没有,有没有办法在一个函数中合并它?

hide(e:any) {
  $('.suggestion').hide();
}
show(e:any) {
  $('.suggestion').show();
}
Run Code Online (Sandbox Code Playgroud)
<section class="search-bar-wrapper" (focusout)="hide($event)" (focusin)="show($event)">
Run Code Online (Sandbox Code Playgroud)

events show hide angular

9
推荐指数
2
解决办法
3万
查看次数

错误TypeError:无法读取未定义的属性"length"

这段代码中有一个错误

<img src="../../../assets/gms-logo.png" alt="logo" routerLink="/overview" alt="website icon">
Run Code Online (Sandbox Code Playgroud)

但是当我检查资产文件夹时,gms-logo.png仍然存在angular-cli.json,资产也存在.路径也是正确的.

最近,我一直在研究搜索功能.所以我的假设是,

即使用户仍未关注输入类型,程序是否也开始搜索?我该如何解决?

下面是我的搜索html以及其建议段的显示

<input type="text" placeholder="Search" (keyup)="onSearch($event.target.value)">        
<div class="suggestion"  *ngIf="results.length > 0">
     <div *ngFor="let result of results ">
          <a href="" target="_blank">
                {{ result.name }}
          </a>
     </div>
</div>
Run Code Online (Sandbox Code Playgroud)

以下是我的组件

results: Object;



 onSearch(name) {
            this.search
            .searchEmployee(name)
            .subscribe(
                name => this.results = name,//alert(searchName),this.route.navigate(['/information/employees/']),
                error => alert(error),
                );
}
Run Code Online (Sandbox Code Playgroud)

typeerror google-developer-tools angular-cli google-developers-console angular

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

错误:文件名必须以.xml或.png结尾

即使我没有选择photothumb.db作为可绘制对象,但我还是收到一条错误消息,说photothumb.db应该以.xml或.png结尾

我的profilesmaller图片是类型png

以下是我的代码

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/profilesmaller"
    tools:context="charlenebuena.guest.HomeFragment">
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

以下是我的Gradle控制台消息

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> C:\Users\Charlene Marie\AndroidStudioProjects\Guest\app\src\main\res\drawable\photothumb.db: Error: The file name must end with .xml or .png

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.72 secs
Run Code Online (Sandbox Code Playgroud)

android android-image android-drawable android-background

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

How To Add Maven Dependency (Android Studio)

I have this code below..

<dependency>
    <groupId>me.gujun.android.taggroup</groupId>
    <artifactId>library</artifactId>
    <version>1.4</version>
    <type>apklib</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)

But where do you put this in Android Studio? I've already placed a dependency in build.gradle which is compile 'me.gujun.android.taggroup:library:1.4@aar'

xml maven maven-dependency-plugin android-studio maven-dependency

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

如何在 HttpClient Angular 7 中使用 finally

在以前的 Angular 版本中,我使用的finally()就像下面的代码一样

constructor(
    private http: Http
) { }

const headers = new Headers({ 'Authorization': this.authenticate.getToken(), 'Content-Type': 'application/json' });
const options = new RequestOptions({ headers: headers });

return this.http.put(Globals.SERVER_URL + '/alert/exempted?_id=' + alertId + '&isExempted=' + status + '&app_id=' + app_id, options )
                .map(this.extractData)
                .catch(this.handleError)
                .finally(() => {
                    this.exceptionSubject.next();
});
Run Code Online (Sandbox Code Playgroud)

但是现在使用 Angular 7 时,我不能再使用它了。如何在代码中插入finally(HttpClient)?这是我现有的代码:

constructor(
    private http: HttpClient
) { }

const header = new HttpHeaders({'Content-Type': 'application/json'}); 
return this.http.get(Globals.ATTENDANCE_URL + '/individual_employment_setting/detail/' + id, { headers: header }) …
Run Code Online (Sandbox Code Playgroud)

finally httpclient angular-http angular angular-httpclient

5
推荐指数
0
解决办法
1232
查看次数

Angular Material Select:如何自定义.mat-select-panel本身

我有使用Angular Material Select的html结构

<mat-form-field class="year-drpdwn-vacay-stock">
    <mat-select placeholder="Year">
        <mat-option>None</mat-option>
        <mat-option *ngFor="let yr of year"  [value]="yr">{{yr}}</mat-option>
    </mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

我放置了一个类,因为我还在其他组件中使用了Select。我尝试添加

::ng-deep .mat-select-panel {
    margin-top: 20%; 
} 
Run Code Online (Sandbox Code Playgroud)

在CSS中进行自定义,但是问题是,包含另一个选择框的其他组件也会受到影响(继承了margin-top CSS)

目前我有这个CSS

.year-drpdwn-vacay-stock mat-select.mat-select :host ::ng-deep .mat-select-panel {
    margin-top: 20%; 
}
Run Code Online (Sandbox Code Playgroud)

但这仍然行不通。

更新

目标:打开选择框后,我希望选项面板向下移动一点,这就是为什么我希望.mat-select-panel最高利润为20%

css material-design angular-material angular-material2 angular

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

如何将输入类型TIME设置为24小时格式?

我有一个使用 Angular Material 的 Angular 7 项目。我还在我的输入标签中使用了时间类型(HTML5)

<input type="time">
Run Code Online (Sandbox Code Playgroud)

但我希望它是 24 小时格式(不显示 AM/PM 选项)。我一直在寻找解决方案,但没有一个适合 Angular Material 项目。

html timepicker angular angular6 angular7

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

材质图片列表错误:@import "@material/feature-targeting/functions";

我想在我的 Angular 项目中使用 mdc-image-list。我收到一个错误:

@import "@material/feature-targeting/functions";
       ^
      Can't find stylesheet to import.
   ?
21 ? @import "@material/feature-targeting/functions";
   ?         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ?
  node_modules/@material/image-list/_mixins.scss 21:9         @import
  node_modules/@material/image-list/mdc-image-list.scss 21:9  @import
  stdin 2:9                                                   root stylesheet
Run Code Online (Sandbox Code Playgroud)

我按照https://material.io/develop/web/components/image-lists/的安装步骤操作,但我仍然收到此错误。我尝试再次删除node_modules和 npm 安装。我不确定我的 sass-loader 是否有问题,因为我使用了 Material 的布局网格,导入了@import "@material/layout-grid/mdc-layout-grid";它并且工作正常。什么可能出错?

sass angular material-components-web

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

Angular 2:如果表单发生变化,则禁用按钮

我想检查我的表单中是否至少有一个字段被更改。如果这种情况为真,disableButton则将设置为true,如果表单中没有更改,则设置为false。以下是我当前的代码:

// this.hold is an array that temporary holds the previous values of 
// the form for comparison of the changes in form

if(this.data.process == 'update') {
   for(const f in form.value){
       if (form.value[f] == this.hold[f])
           this.disableButton = true;
       else
           this.disableButton = false;
   }
}
Run Code Online (Sandbox Code Playgroud)

问题是,该按钮仅在更改所有字段时禁用。我应该在我的条件或 for 循环中添加什么?

forms field typescript angular angular-forms

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

bash: npm: 命令未找到

当我检查节点的版本时,它说

v8.0.0
Run Code Online (Sandbox Code Playgroud)

但是当我检查 NPM 的版本时,它说

bash: npm: command not found
Run Code Online (Sandbox Code Playgroud)

以前,我的操作是

npm install -g "@angular/cli"

那是它始终显示npm: command not found消息的时候。

我尝试寻找可能的解决方案,但没有一个像brew和其他人那样有效。

node.js npm angular-cli angular

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

角度2:在另一个组件中显示搜索结果

我的搜索字段位于单独的组件上。搜索时在建议列表上显示名称没有问题,因为我没有在其他组件中显示它们。

搜寻HTML

<input type="text" placeholder="Search" (keyup)="getSuggestion($event.target.value)">
<div class="suggestion" *ngIf="results.length > 0 && suggest === true">
     <div *ngFor="let result of results" class="search-res" (click)="showEmployee(result._id)"> {{ result.name }} </div>
</div>
<div class="suggestion" *ngIf="results.length === 0 && suggest === true">
     <div> No results found </div>
</div>
Run Code Online (Sandbox Code Playgroud)

搜索组件

getSuggestion(name) {
    $('.suggestion').show();
    this.searchService
        .getSuggestion(name)
        .subscribe(
            name => this.results = name,
            error => alert(error),
        );
  }
Run Code Online (Sandbox Code Playgroud)

但是,如果要在change事件中将其显示在另一个组件(列表组件)中怎么办?

我应该在输入字段中添加什么作为函数调用?并且我应该在SearchComponent中放置什么以便结果可以显示在List Component中?

SearchService

getSuggestion(name:string): Observable<any> {
        return this.http
        .get(this.serverUrl + 'name/' + name)
        .map(this.extractData)
        .catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)

methods search angular-template angular2-components angular

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

Angular 2:简单 *ngFor 不起作用

我的里面有这个app/component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <ul>
      <li *ngFor="let course of courses">
        {{ course }}
      </li>
    </ul>
  `,
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  course = ['Course 1', 'Course 2', 'Course 3'];
}
Run Code Online (Sandbox Code Playgroud)

在我的 app.module.ts 中,我还导入了必要的东西

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CommonModule
  ],
  providers: [], …
Run Code Online (Sandbox Code Playgroud)

angular-ng angular2-databinding angular

0
推荐指数
1
解决办法
1217
查看次数