angular4 note

纪录作为新手,用新版angular遇到的一些细节点

1.  .angular-cli.json文件

     一开始没注意这个文件干啥的,直到我发现有个第三方js,我既没有在index.html里看到引用,也没看到在js代码里有import,找了好久,在这个文件下找到。该文件用于angular命令配置参数,具体各个参数意思,参考这篇 http://www.cnblogs.com/qingming/p/6961548.html

2.父子组件通信,几个关键字, @ViewChild @Input @Output EventEmitter(子组建事件回调通知父组件,父组件属性,和方法绑定和子组件通信) 具体实现百度,很简单。

   层级较深的组件通信可以用service(其实可以理解全局变量),另外事件发送也是一种方法(不推荐)。

3.跨域 

   "start": "ng serve --port 4222  --proxy-config proxy-config.json",

        本地加个proxy-config.json,配置代理

       

{
  "/api": {
    "target": "",
    "secure": false
  },
  "/login": {
    "target": "",
    "secure": false
  },
  "/logout": {
    "target": "",
    "secure": false
  }
}
原文地址:https://www.cnblogs.com/johnzhu/p/7347271.html