小编Aw3*_*ame的帖子

Angular 2 - 尝试从select中获取值时未定义

我是Angular 2的新手,我遇到了这个问题.我有一个选项有3个选项,我无法获得其中一个选项的价值.

html:

<select [(ngModel)]="product_type" class="form-control" (ngModelChange)="getType()">           
        <option [ngValue]="A"><span>ALL</span></option> 
        <option [ngValue]="T"><span>Type product</span></option>
        <option [ngValue]="E"><span>Standart product</span></option>            
    </select>
Run Code Online (Sandbox Code Playgroud)

Component.ts:

 type_product:string;
/*...*/
 getType(){
   this.type_product= ""+this.type_product;
  console.log(this.type_product);

}
Run Code Online (Sandbox Code Playgroud)

当我执行它时,日志显示未定义.我做错了什么?谢谢

angular

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

从Angular 2应用程序发布POST时c# - 405(方法不允许)

我对这个问题有点绝望.我是angular 2和.net的新手,我试图构建一个简单的应用程序.我用c#编写了api休息.当我从角度调用GET方法时,它工作正常,但不是POST方法.我一直收到405(方法不允许),但是如果我用邮递员打电话的话都可以.我看到同样问题的很多问题,但它们对我不起作用.我启用了CORS.这是我的代码:

    sendPtipo(delegacion,municipio,ejercicio,recinto,tipo){
    let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
    let options = new RequestOptions({ headers: headers });
    let urlPtipo ='http://localhost:50790/ApiProductoTipo/CalculaPTRecinto';
    let body ='delegacion='+delegacion+'&municipio='+municipio+'&recinto='+recinto+'&ejercicio='+ejercicio+'&tipo'+tipo;

return this._http.post(urlPtipo , body , options)
               .map(data => {alert('ok');})
               .catch(this.handleError);
}

private extractData(res: Response) {
    let body = res.json();
    return body.data || {};
}

private handleError(error: Response) {
    console.error(error);
    return Observable.throw(error.json().error || 'Server error');
}}
Run Code Online (Sandbox Code Playgroud)

在C#休息

using System.Collections.Generic;
using System.Web.Http;
using AppName.Models;
using AppName.Service;
using System.Linq;
using AppName.ViewModels;
using System.Net.Http;
using System.Net;
using System.Web.Http.Cors; …
Run Code Online (Sandbox Code Playgroud)

c# api rest post angular

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

角度-this.function不是函数

我对此感到绝望。我有一个获取数据并使用此数据的信息呈现地图的组件。一切都很好。我在此地图上放置了标记,我想在标记中执行点击功能。这些函数调用组件中定义的另一个函数,并带给我数据以模态形式显示它。但是,当我单击标记时,出现以下错误:

this.getInfoAlteracion不是一个函数

我不知道为什么 我证明了很多事情,但看不到错误。这是我的代码:

import { Component, OnInit } from '@angular/core';
import * as L from 'leaflet';
import 'leaflet.markercluster';
import { MapService } from './services';
import * as global from 'app/globals';
import { Alteracion } from './dto/alteracion';

@Component({
  selector: 'map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit {
  public alteraciones: Alteracion[] = [];
  public alteracion: Alteracion[] = [];

  constructor(private mapService: MapService) {}

  ngOnInit() {
    this.getAlteraciones();
  }


  getAlteraciones() {
    this.mapService.getListAlteraciones(11, 1).subscribe(
      result => {
        this.alteraciones = result;
        this.renderMap(); …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

MatSnackBar 中的样式从组件打开

我正在寻找一种方法来执行以下操作:要显示通知,我想实现一个自定义 SnackBar。我按照官方文档(这里)创建了一个简单的 Snackbar,带有一些自定义配置。

this.snackBar.open('Message one', 'OK', configSuccess);

export const configSuccess: MatSnackBarConfig = {
  panelClass: 'style-success',
  duration: 10000,
  horizontalPosition: 'left',
  verticalPosition: 'bottom'
};
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我想在我的 SnackBar 中显示不同的显示(特别是发送数据并显示两个按钮)。按照文档,我创建了一个组件并从中打开我的 SnackBar:

/*...*/    
this.snackBar.openFromComponent(SnackbarMessageComponent, {
              data: 'Message one',
            });
/*...*/

@Component({
  selector: 'app-snackbar-message',
  templateUrl: './snackbar-message.component.html',
  styleUrls: ['./snackbar-message.component.scss']
})
export class SnackbarMessageComponent implements OnInit {

  constructor(@Inject(MAT_SNACK_BAR_DATA) public data: any) { }

  ngOnInit() {
  }
Run Code Online (Sandbox Code Playgroud)

一切正常,但现在我遇到了问题。我想将我之前定义的配置(config Success例如)传递给这个新的 SnackBar ,但是在官方文档和 Google 中我没有找到任何东西。

有没有办法做到这一点而不必全局定义它?有人可以指导我或告诉我去哪里吗?提前致谢!

angular-material angular-material2 angular

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