将解析程序数据分配给字符串键

时间:2017-04-13 00:28:14

标签: angular

我一直在学习如何在Angular路由器中使用解析器,而且我与docs之间存在差异,我无法弄清楚。

据我所知,除了使用Promise的文档以外,我已经从文档/指南中复制了解析器,并使用了Observer:

  Collecting hashlib
    Using cached hashlib-20081119.zip
      Complete output from command python setup.py egg_info:
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/__init__.py", line 12, in <module>
    import setuptools.version
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/setuptools/version.py", line 1, in <module>
    import pkg_resources
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 36, in <module>
    import email.parser
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser, BytesFeedParser
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/feedparser.py", line 27, in <module>
    from email import message
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/message.py", line 16, in <module>
    from email import utils
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/utils.py", line 28, in <module>
    import random
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/random.py", line 45, in <module>
    from hashlib import sha512 as _sha512
  File "/private/var/folders/nw/flrm4y0d499fk5xr2ppxk4sr0000gn/T/pip-build-lv720o4k/hashlib/hashlib.py", line 80
    raise ValueError, "unsupported hash type"
                    ^
SyntaxError: invalid syntax

----------------------------------------
  Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/nw/flrm4y0d499fk5xr2ppxk4sr0000gn/T/pip-build-lv720o4k/hashlib/ 

但是,在我的组件中,当我尝试访问数据时:

export class OrgResolver implements Resolve<Org> {

    constructor(private router: Router, private orgService: OrgService) { }

    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Org> {
        return this.orgService.getOrgData(route.params['org']).map((org: Org) => {
            if (org === null) {
                this.router.navigate(['/']);
                return null;
            } else {
                return org;
            }
        });
    }

}

我看到ngOnInit() { this.route.data.subscribe((data: { org: Org }) => { this.org = data.org; console.log(data); }); } 是一个只有一个密钥的对象,0。在文档中,密钥以某种方式设置为“危机”,但我似乎无法想象如何。我觉得我必须假设data在其他情况下可能包含其他密钥,所以我无法确定0是我想要的密钥。

我是否遗漏了使用旋转变压器的事情?

1 个答案:

答案 0 :(得分:0)

我没有意识到问题出在路线配置中。最初,我正在传递resolve数组:

resolve: [OrgResolver]

我没有意识到我想传递一个对象,关键是如何在data中表示:

resolve: { org: OrgResolver }