小编Mic*_*ryl的帖子

IntelliJ IDEA报告未解决的变量TypeScript错误,但不允许':any'

我在Angular 2应用程序中具有以下TypeScript代码。

   constructor(private windows:WindowService, private http:Http) {
        http.get('config.json')
            .map(res => res.json())
            .subscribe(config => {
                this.oAuthCallbackUrl = config.callbackUrl; // here
                this.oAuthTokenUrl = config.implicitGrantUrl; // here
                this.oAuthTokenUrl = this.oAuthTokenUrl
                    .replace('__callbackUrl__', config.callbackUrl) // here
                    .replace('__clientId__', config.clientId) // here
                    .replace('__scopes__', config.scopes); // here
                this.oAuthUserUrl = config.userInfoUrl; // here
                this.oAuthUserNameField = config.userInfoNameField; // here
            })
    }
Run Code Online (Sandbox Code Playgroud)

我到过的每个地方// here都会从IDE中收到一条错误消息,提示我有一个“未解析的变量”,例如unresolved variable callbackUrl

问题在于此配置对象是应用程序获取的JSON文件的结果,我不知道如何提前定义其类型。

我以为我可以将订阅行更改为show .subscribe(config:any => {或其他内容,但这没有用。

该代码可以正常编译。一切都可以在浏览器中(并通过Webpack)正常运行。我只是想摆脱IDE中的错误,而不必添加7条//noinspection TypeScriptUnresolvedVariable注释来压制它们。

intellij-idea webstorm typescript

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

Angular2组件不检测路由参数更新(路由器3.0)

我有一个小的Plunk,我正在使用Angular 2中目前可用的新的Router 3.0 alpha.它一般运行良好,但问题是,一旦我点击一个路由到'detail'的链接具有特定ID的组件,当我单击具有不同ID的其他链接时,它永远不会更改.该组件永远不会被重新实例化,因此它只会在第一次加载时显示它被传递的内容.

这是有问题的组件:

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ContactsService } from './contacts.service';

@Component({
  selector: 'contacts-detail',
  template: `
    <h2>{{contact.name}}</h2>
  `
})
export class ContactsDetailComponent implements OnInit { 

  constructor(private contactsService: ContactsService, private route: ActivatedRoute) {
  }

  ngOnInit() {
    this.contact = this.contactsService.getContact(this.route.snapshot.params.id);
    console.log('Fetching user', this.route.snapshot.params.id);
  }
}
Run Code Online (Sandbox Code Playgroud)

以下是Plunk展示了这个问题.单击一个作者姓名,然后单击另一个作者名称以查看其不更改.

javascript angular2-routing angular2-components angular2-router3 angular

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

使用带有 Promise 的 ldapjs

我想将以下代码转换为使用 Promise。它正在工作并输出活动目录中的用户属性。

var client = ldap.createClient({
  url: ldap_url
});

client.bind(ldap_username, ldap_password, function (err) {
    client.search(ldap_dn_search, opts, function (err, search) {
        search.on('searchEntry', function (entry) {
          var user = entry.object;
          // It is working!!!. It outputs all user attributes.
          console.log(user);
        });

    });
}); 
Run Code Online (Sandbox Code Playgroud)

以下是我的尝试,但它没有输出任何内容。

var Promise = require('promise');
var client_bind = Promise.denodeify(client.bind);
var client_search = Promise.denodeify(client.search);

client_bind(ldap_username, ldap_password)
.then(function(err){
  client_search(ldap_dn_search, opts)
    .then(function(search){
      var search_on = Promise.denodeify(search.on);
      search_on('searchEntry')
        .then(function(entry){
          var user = entry.object;

          // It doesn't output anything !!!
          console.log(user);
        });
      });

    });
Run Code Online (Sandbox Code Playgroud)

javascript node.js promise ldapjs

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

JAVA:静态方法在执行期间是否会对性能造成相当大的影响?

我有两个问题已经在脑子里转了一段时间,我希望有些知识渊博的人可以为我回答:)

  1. 在代码执行期间(时间)使用静态方法对性能有好坏吗?
  2. 记忆怎么样?他们使用的内存多于实例方法吗?

java static-methods jvm execution-time

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