zoukankan      html  css  js  c++  java
  • Angular 开发问题记录

    1,can't bind to 'ngModel' since it isn't a known property of 'input'

    解决: ngModel 指令存在于 npm package: @angular/forms中,需要引入
    import { FormsModule } from "@angular/forms";

    并加入到imports中:

    imports: [
      FormsModule
    ]

    2,angular cli报错:TypeError: Cannot read property 'NullLogger' of undefined

    解决: 重新安装angular-cli

    npm uninstall -g angular-cli
    npm cache clean --force
    npm install -g @angular/cli@latest

    3,angular-cli 如何使用代理api

    解决:

    angular-cli启动前端项目的地址例如为:http://localhost:4200,后台服务的地址为http://localhost:9999,如果直接将请求地址写成http://localhost:9999/api,会发生CORS跨域错误。

    首先在根目录下新建proxy.config.json:

    {
       "/api-admin": {
          "target": "http://localhost:9999",
          "changeOrigin":true
       }
    }

    然后在package.json中,配置

    "start": "ng serve --proxy proxy.config.json"

    此时对后端的请求就会被代理到9999端口。

    在http请求时如下,

     this.dataSource = this.http.get("/api-admin/login?username="+this.username+"&password="+this.password,{}).map((res)=> res.json());
     this.dataSource.subscribe(function (res) {
         console.log(res);
     }, function (err) {
         console.log(err);
     });

  • 相关阅读:
    找到排序矩阵中从小到大第K个数字
    使用VSCODE开发UE4
    UE4添加模块
    游戏串流
    DIY Arduino 方向盘
    免费/开源软件推荐
    把引擎插件变成工程插件
    MergeActors技巧
    烘焙卡在99%
    UMG里没有"Prefab"怎么办?
  • 原文地址:https://www.cnblogs.com/easonw/p/9210413.html
Copyright © 2011-2022 走看看