小编Vla*_*tko的帖子

Angular 2嵌套路由解析执行

例如,如果我有以下路线组织:

const appRoutes: Routes = [
    {
        path: "",
        component: AppComponent,
        resolve: {
            app: AppResolver
        },
        children: [
            {
                path: "",
                component: NestedComponent,
                resolve: {
                    subscribers: NestedResolver
                }
            }
        ]
    }
];
Run Code Online (Sandbox Code Playgroud)

和以下解析器:

export class AppResolver implements Resolve<any> {
    constructor(private appService: AppService) {}
    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
        return this.appService.getAppData();
    }
}
Run Code Online (Sandbox Code Playgroud)
export class NestedResolver implements Resolve<any> {
    constructor(private nestedService: NestedService) {}
    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
        console.log(route.parent.data); //when this is executed route.parent.data is empty :(
        return this.nestedService.getNestedData(); …
Run Code Online (Sandbox Code Playgroud)

router resolve typescript angular

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

IE和Socket.io的兼容性

我在这里做了一些聊天示例:http://psitsmike.com/2011/09/node-js-and-socket-io-chat-tutorial/

当我使用Chrome和Firefox时,一切都像魅力一样.使用IE9或Opera时,某些socket.io事件不会触发(例如断开连接)或触发太晚,并且数据接收速度太慢.

我用npm方法安装了node.js和socket.io模块.

请帮忙.

opera internet-explorer node.js socket.io

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

Php路由解析器URL的结尾

我为自己的php-mvc-framework编写了一个小的php url解析器,我在以下代码中需要一些帮助:

<?php
class Route{

private $routes = [];

public function __construct(){}

public function addRoute($method, $url, $callback){
    $this->routes[] = array('method' => $method, 
                          'url' => $url, 
                          'callback' => $callback);
}

public function doRouting(){
    $reqUrl = $_SERVER['REQUEST_URI'];
    $reqMet = $_SERVER['REQUEST_METHOD'];
    foreach($this->routes as  $route) {

        // convert urls like '/users/:uid/posts/:pid' to regular expression      
        $pattern = "@^" . preg_replace('/\\\:[a-zA-Z0-9\_\-]+/', '([a-zA-Z0-9\-\_]+)', preg_quote($route['url'])) . "$@D";
        $matches = array();

        if($reqMet == $route['method'] && preg_match($pattern, $reqUrl, $matches)) {

            // remove the first match
            array_shift($matches);
            // call the callback …
Run Code Online (Sandbox Code Playgroud)

php router

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

如何从已知的URL格式解析令牌?

我在PHP中有一个字符串,它反映了为网站选择的URL路由格式 - 它根据方案中传递的索引/指令动态构建内容.例如,典型的请求格式可能如下所示:

$str = '/something-new/:id/goto/:new_id/full/page/:num/';
Run Code Online (Sandbox Code Playgroud)

我想要提取的数据是每个索引的实体名称,它们总是以冒号开头:.我不确定最好的方法 - "分裂"字符串似乎很麻烦.将这些结果数据导入数组的最简单方法是什么?

$arr = [
    [0] => 'id', 
    [1] => 'new_id', 
    [2] => 'num'
];
Run Code Online (Sandbox Code Playgroud)

php regex arrays string

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