小编hak*_*ian的帖子

Angular 2在构造函数外部注入依赖项

我正在深入研究Angular 2中的DI.我正在使用泛型子类型实现一个REST-Client,用于具体的数据类型,如下所示:

class RESTClient<T>{
    constructor() {
        var inj =  ReflectiveInjector.resolveAndCreate([HTTP_PROVIDERS]);
        this.http = inj.get(Http);
        this.conf = RESTConfiguration;
    }
}
class BookClient extends RESTClient<Book>{      
    constructor(){
        // since I dont want to inject the HTTP Providers here, I'm using a custom    injector in the super class
        super();
    }
}

class WriterClient extends RESTClient<Writer>{      
    ...
    ...
}
Run Code Online (Sandbox Code Playgroud)

据我所知,在超类REST-Service注入的所有RESTClient之间将共享一个http服务.

现在我希望有一个RESTConfiguration类:

@Injectable()
export class RESTConfiguration {
    get baseURL() {
     return this._baseURL;
    }

    set baseURL(value) {
        alert("sets value to"+value);
        this._baseURL = value;
    }

    private _baseURL;

}
Run Code Online (Sandbox Code Playgroud)

它应该在主应用程序中配置如下: …

singleton dependency-injection typescript angular

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

获取NSViewController的View是否是自定义类?

我使用以下代码从我的控制器中获取我的视图:

CollectionItemView *myView = [self view]; 
Run Code Online (Sandbox Code Playgroud)

这很好用,但我收到了警告Incompatible pointer types initializing CollectionItemView __strong with an expression of type NSView.我理解为什么我得到这个但是可以忽略它或者我应该覆盖视图属性吗?

夹头

xcode cocoa objective-c nsview nsviewcontroller

5
推荐指数
1
解决办法
272
查看次数