我正在使用Webpack和Visual Studio Code,以避免以下情况:
import { AuthenticationService } from '../../../services/authentication/service';
Run Code Online (Sandbox Code Playgroud)
我在webpack.config上创建了别名,所以我可以使用:
import { AuthenticationService } from 'services/authentication/service';
Run Code Online (Sandbox Code Playgroud)
但是,通过这样做,Visual Code无法检测到我的代码,因此我失去了我的类的智能感知.
有没有人有解决方案,有没有办法让VS代码读取webpack.config并识别带别名的路径?
提前致谢
我试图将回调函数绑定到一个指令,当事件被触发时,父组件的属性是未定义的
app.ts
import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {MyComponent} from './my-component';
@Component({
selector: 'my-app',
template: `
<button (click)="appOnClick('CLICK FROM APP')">BUTTOM OUTSIDE COMPONENT</button>
<br><br>
<my-component [onClick]="appOnClick"></my-component>`,
directives: [MyComponent]
})
export class MyApp {
public theBoundCallback: Function;
test:string = "THIS SHOULD HAVE A VALUE";
public ngOnInit(){
this.theBoundCallback = this.appOnClick.bind(this);
}
appOnClick(someText){
console.log(someText);
console.log(this.test);
}
}
bootstrap(MyApp);
Run Code Online (Sandbox Code Playgroud)
我-component.ts
import {Component, Input} from 'angular2/core';
@Component({
selector: 'my-component',
template: `<button (click)="onClick('CLICK FROM COMPONENT')">BUTTOM INSIDE COMPONENT</button>`
})
export class MyComponent{
@Input() onClick: Function; …Run Code Online (Sandbox Code Playgroud)