小编Dav*_*ots的帖子

Angular TypeError:无法在Promise subscription()中读取null的属性“ length”

我正在调用API端点并收到错误,但是使用console.log时无法查看错误,因为在下面出现错误。还有另一种方法来获取错误吗?

错误

TypeError: Cannot read property 'length' of null
    at http.js:109
    at Array.forEach (<anonymous>)
    at HttpHeaders.lazyInit (http.js:103)
    at HttpHeaders.init (http.js:251)
    at HttpHeaders.forEach (http.js:354)
    at Observable._subscribe (http.js:2153)
    at Observable._trySubscribe (Observable.js:172)
    at Observable.subscribe (Observable.js:160)
    at Object.subscribeToResult (subscribeToResult.js:23)
    at MergeMapSubscriber._innerSub (mergeMap.js:132)
Run Code Online (Sandbox Code Playgroud)

供应商

    import { HttpClient } from '@angular/common/http';
    import { Http, Headers , RequestOptions } from '@angular/http';
    import { Injectable } from '@angular/core';

    @Injectable()
    export class GamesProvider {

    // API url 
    apiUrl = 'http://xxxxx.com/api';

    headers : any;
    options: any;

    this.headers =  new Headers(); …
Run Code Online (Sandbox Code Playgroud)

angular

4
推荐指数
2
解决办法
4421
查看次数

静态变量和静态方法之间的区别

我知道当你使用静态变量时,它的值会在所有用户之间共享.

static string testValue = "";
protected void SomeMethod(object sender, EventArgs e)
{
    testValue = TextBox1.Text;        
    string value = TestClass.returnString(TextBox1.Text); // <-- return from a static method
}
Run Code Online (Sandbox Code Playgroud)

因此,在这种情况下,如果一个用户访问网站并将值放入文本框,则testValue当另一个用户在文本框中输入内容时,该字符串将被另一个值覆盖.(我认为?)

我现在有这个班:

public class TestClass
{
  public static string returnString(string msg)
  {
    return msg;
  }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:如果我使用静态方法,那么该方法的返回值是否也为所有用户共享?或者每个用户总是一个"独特"的价值?

假设这个方法被五个不同的用户调用五次,这个静态方法会返回特定用户输入的值,还是一个用户可能获得另一个用户输入的值?

c# asp.net webforms

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

角构建index.html不起作用

我尝试在浏览器中打开index.html时,已采用了角度项目的构建方式,并获得了dist文件夹。我遇到以下错误,例如无法加载资源和找不到inline.bundle.js和polyfil的文件。 bundle.js和许多文件。 在此处输入图片说明 虽然此文件已添加到脚本标签中,但我没有更改此文件的路径仍然无法正常工作。但是如果我从实时服务器运行此文件,它将正常工作。 在此处输入图片说明 解释为什么没有服务器它不能正常工作?为什么不加载js文件inline.bundle.js,polyfill.bundle.js?

javascript node.js angular nodejs-liveserver

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

如何使用 pgAdmin 连接 docker 容器上的 postgresql 镜像?

我刚刚从 GitHub 克隆了一个项目,在自述文件中它要求我运行docker-compose upPostgreSQL 映像...

我假设运行命令后,PostgreSQL 服务器映像将使用端口 5432 在我的电脑上的 Docker 容器中启动。然后我运行npm installnpm start启动项目(数据库表将使用 ORM 框架自动创建)。但是,当我打开 pgAdmin 连接到服务器时,它说它已成功连接,但我找不到创建的那些表。这里我猜测 pgAdmin 没有连接 5432 上的 PostgreSQL 服务器(Docker 镜像)...所以我的问题是是否可以使用本地电脑中安装的 pgAmin 连接到已经运行的 PostgreSQL 服务器 Docker 镜像,映射到我本地PC的端口5432?

postgresql docker

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

Mixins可能未在控制指令或其他mixin中定义

我尝试安装npm包.所有包都安装正确.但是当我尝试使用npm start当时运行应用程序时,出现以下错误:

错误在./node_modules/css-loader?{"sourceMap":false,"importLoaders":1}!./node_modules/postcss-loader?{"ident":"postcss"}!./node_modules/sass-loader/ lib/loader.js?{"sourceMap":false,"precision":8,"includePaths":[]}!./ src/styles.scss模块构建失败:
未定义
^
Mixins可能未在控制指令或其他内定义混入.
在D:\ DailyJS\CIDE_SCHOOL_DEV \node_modules\@angular\material_theming.scss(第2440行,第10列)
错误:
未定义
^
Mixins可能未在控制指令或其他mixin中定义.
在D:\ DailyJS\CIDE_SCHOOL_DEV \node_modules\@angular\material_theming.scss(第2440行,第10行)
的options.error(D:\ DailyJS\CIDE_SCHOOL_DEV \node_modules \node-sass\lib\index.js:291:26) )@ ./src/styles.scss 4:14-187
@ multi ./node_modules/font-awesome/scss/font-awesome.scss ./src/styles.scss
webpack:无法编译.

我不知道为什么会这样?以前我从Github克隆了存储库,然后使用安装了npm软件包npm install.然后它奏效了.

但今天,它给出了这个错误:

Mixins可能未在控制指令或其他mixin中定义.

node-sass

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

角-反应形式-FormGroupName内的FormGroupName

我有一个从API返回的嵌套JSON响应,其结构与我需要在模板上显示的方式不同,例如:

@Component({
  selector: 'reactive-form-example',
  styles: ['./reactive-form-example.component.css'],
  template: `
    <form [formGroup]="form" (ngSubmit)="onSubmit()">
        <div formGroupName="first">
            <input type="text" placeholder="some id" formControlName="someId">
            <div formGroupName="second">
                <input type="text" placeholder="some text" formControlName="someText">
            </div>
        </div>
    </form>
  `
})
export class ReactiveFormExampleComponent {
    form = new FormGroup({
        first: new FormGroup({
            someId: new FormControl('587824')
        }),
        second: new FormGroup({
            someText: new FormControl('the sky is blue')
        })
    });
    onSubmit(value) {
        console.log('Submit', this.form.value);
    }
}
Run Code Online (Sandbox Code Playgroud)

问题:是否有可能formGroupName嵌套在另一个对象中formGroupName,或者是否有更好的方法使用反应形式来实现相同的结果?

angular angular-reactive-forms

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

服务未返回数据

我有一个服务,其方法如下:

getTotalCountries() {
    this.http.get("country").subscribe((response) => {
      console.log(response.json());//it is displaying all the data which is return by API
      return response.json();           
    });
}
Run Code Online (Sandbox Code Playgroud)

以类似的方式,我在组件中具有如下功能:

public users: any

countCountry() {
    this.count=this.user.getTotalCountries();
    console.log(this.count) //it is not returning any data;
}
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么它不返回component.ts. 有人可以帮我吗?

typescript angular

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

spa.UseAngularCliServer()中间件如何服务网页?

我使用Visual Studio 2017(版本15.7.2)创建了.Net Core 2.1 Angular应用程序 在此处输入图片说明

我想知道spa.UseAngularCliServer()如何在开发模式下提供页面。

  1. 在调试模式下,尽管网页已正常加载,但ClientApp或wwwroot文件夹中没有“ dist”文件夹。dist文件夹在哪里?

  2. 看来,spa中间件启动了angular-cli dev服务器,但该网页实际上是由IIS Express托管的。“ ng服务”与IIS Express有何关系?

形成starup.cs

app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
Run Code Online (Sandbox Code Playgroud)

.net-core asp.net-core angular-cli angular

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

TypeScript 中的 findIndex 数组方法

我对 Angular 4 开发非常陌生。我遇到的someArray.findIndex()不是函数。如何添加这个.findIndex()在 TypeScript 中添加此 javascript 函数。

我正在构建一个日历组件,以下函数给了我错误

WEBPACK_IMPORTED_MODULE_2_lodash .findIndex 不是 CalendarComponent.isSelected 中的函数(calendar.component.ts:4

isSelected(date: moment.Moment): boolean {
    return _.findIndex(this.selectedDates, (selectedDate) => {
      return moment(date).isSame(selectedDate.mDate, 'day');
    }) > -1;
  }
Run Code Online (Sandbox Code Playgroud)

太感谢了。

javascript typescript angular

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

Angular 5中RequestOptions不推荐使用的符号错误

我正在尝试使Angular 4中的代码适应Angular5。我进行了很多更改,但是关于出现错误RequestOptions。该代码是关于身份验证的,这是我出现错误的地方:

  import { Injectable } from '@angular/core';
   import { RequestOptions} from '@angular/http';
   import {User} from '../model/model.user';
   import 'rxjs/add/operator/map';
    import {HttpClient, HttpHeaders} from '@angular/common/http';

  @Injectable()
  export class AuthService {
  constructor(public http: HttpClient) { }

    public logIn(user: User) {

const headers = new HttpHeaders();
headers.append('Accept', 'application/json')
// creating base64 encoded String from user name and password
const base64Credential: string = btoa( user.username + ':' + user.password);
headers.append('Authorization', 'Basic ' + base64Credential);
     // this is where i'm having a problem …
Run Code Online (Sandbox Code Playgroud)

angular5

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