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);
     });

  • 相关阅读:
    poli-java开源BI软件
    Spring Boot 教程
    微信小程序支持windows PC版了
    Java-JDK-windows和linux版-百度云下载
    ssh -i 密钥文件无法登陆问题
    锐捷交换机18010-X端口假死现象
    zabbix4.4安装
    yum只下载不安装
    openstack迁移计算节点所有云主机
    ceph SSD HDD分离与openstack调用
  • 原文地址:https://www.cnblogs.com/easonw/p/9210413.html
Copyright © 2011-2022 走看看