小编net*_*tik的帖子

角度路由器中全局可用的 url 参数

我正在尝试构建一个类似于谷歌地图的以地图为中心的应用程序。所以主要有一个地图,并且根据 url 路由,在一个小侧面板内加载一个组件。

export const routes: Routes = [
    {path: 'home/:coordinates', component: HomeComponent},
    {path: 'dashboard/:coordinates', component: DashboardComponent},
    {path: 'utils/:coordinates', component: UtilsDemo},
];
Run Code Online (Sandbox Code Playgroud)

我想要实现的目标类似于谷歌地图:

/home/@54.072,-2.899 --> 加载HomeComponent并导航到坐标 54.072,-2.899

/dashboard/@53.123,2.345--> 加载DashboardComponent并导航到坐标 54.123,2.345

但是,:coordinates参数不应该是组件的本地参数,而应该是全局的。否则我必须在每个组件内完成导航部分。

换句话说:如果我这样做:

this.route.params.subscribe(params => {
   console.log(params['coordinates']);
});
Run Code Online (Sandbox Code Playgroud)

从内部来看AppComponent,参数未定义。它仅在每个特定组件内部起作用。

Angular5 有什么办法可以实现这一点吗?

javascript typescript angular angular-router

3
推荐指数
1
解决办法
2092
查看次数

以正确的顺序迭代ConcurrentHashMap

我用a ConcurrentHashMap来存储英文单词及其在文本中的出现次数.

private Map<String, Integer> _vocab = new ConcurrentHashMap<String,Integer>();
Run Code Online (Sandbox Code Playgroud)

我需要按降序对值进行排序,所以我做了:

   public void sort(){
        this._vocab = this._vocab.entrySet()
                .stream()
                .sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
                .collect(
                        toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2,
                                LinkedHashMap::new));
    }
Run Code Online (Sandbox Code Playgroud)

这似乎有效.但是,现在我想将hashmap限制​​为例如1000个元素,因为我只对前1000个条目感兴趣:

public void limitToNElements(int n){
    ConcurrentHashMap<String, Integer> res = new ConcurrentHashMap<String, Integer>();

    Iterator it = this._vocab.entrySet().iterator();
    int i = 0;
    while (it.hasNext() && i < n) {
        Map.Entry pair = (Map.Entry)it.next();
        String word = (String)pair.getKey();
        res.put((String)pair.getKey(), (Integer)pair.getValue());

        i += 1;
    }

    this._vocab = res;
}
Run Code Online (Sandbox Code Playgroud)

问题是,迭代器不是以正确的顺序迭代,而是随机迭代.

所以我读到只有这样LinkedHashMaps工作,但由于没有Concurrent版本,我害怕自己做同步,我想知道是否有任何解决方法来实现我想要的?

编辑:我使用了HashMap,因为插入/发生计数非常简单:

for(String word: …
Run Code Online (Sandbox Code Playgroud)

java data-structures

2
推荐指数
1
解决办法
444
查看次数

C++ WinAPI - 在windows关闭之前清理终止进程?

通常,WM_CLOSE在使用GUI窗口时,您可以捕获事件以在应用程序终止之前执行清理任务.

但是,如果我的应用程序只在后台运行,并且只有当Windows关闭时才终止进程 - 有没有办法捕获此事件并在进程终止之前执行一些清理?

我知道不可能干预任务管理器流程结束.但是关闭后我才注意到有shutdown一个shutdown /F命令.

c++ windows winapi

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

Angular2 - 等待服务变量初始化

应用

  • MapViewComponent
  • SearchComponent(需要MapViewComponent的对象)
  • 地图服务

到目前为止,我放置了s模板SearchComponent内部,MapViewComponent以便我可以将它传递给SearchComponent使用@Inject(forwardRef(() => MapViewComponent)).但是由于搜索组件应该显示在布局/ HTML DOM中的其他位置,我想我必须使用服务将其传递MapViewComponent给搜索.

MapViewComponent.ts:

export class MapViewComponent {
    @Output() onMapViewCreated = new EventEmitter();

    private _view: any = null;      

    constructor(private mapService: MapService, private elRef: ElementRef) {
    }          

    ngOnInit() {
        this._view = new MapView({
            container: this.elRef.nativeElement.firstChild,
            map: this._mapService.map,
            center: [5.44, 36.947974],
            rotation: 0,
            autoResize: true
        })

        this._view.then((view) => {
            this.onMapViewCreated.next(view);
            this._mapService.setView(view);
        });
Run Code Online (Sandbox Code Playgroud)

SearchComponent.ts:

export class SearchComponent {

    constructor(private elRef:ElementRef, private mapService: MapService ) {
       var view …
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular

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

关于$运算符和括号的混淆

我正在通过第一本haskell书并与$运营商斗争:

以下行有效:

map (>= 16) . take 5 $ iterate  (\x -> x^2) 2
Run Code Online (Sandbox Code Playgroud)

但是,以下内容不是:

map (>= 16) . take 5 (iterate  (\x -> x^2) 2)
Run Code Online (Sandbox Code Playgroud)

可能的原因:`take'应用于太多参数

我没有在这里看到问题.take采用int和列表.据我所知,我提供了两个论点.

如果我想避开$操作员,我该怎么办?

haskell

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