小编sel*_*lf.的帖子

如何使输入可观察?

我有一个带有一些输入的组件,我希望在它发生变化时得到通知.我目前正在通过实现ngOnChanges和确定哪些输入已更改来工作.但是,我更喜欢将我的输入声明设置为@Input('select-values') selectValues:Observable<any>.这将允许我订阅以更清洁的方式发生的任何新变化.

ngOnInit() {
    this.selectValues.subscribe(() => console.log('yay!'));
}
Run Code Online (Sandbox Code Playgroud)

这个问题是我得到了例外TypeError: this.selectValues.subscribe is not a function.

刚刚发现这也有效 - 组件交互.使用setter拦截输入属性更改.

angular

23
推荐指数
3
解决办法
2万
查看次数

当__eq__未被调用时,为什么我的对象从列表中正确删除?

我有以下代码,这让我抓狂 -

class Element:
    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return self.name

def eq(self, other):
    print('comparing {} to {} ({})'.format(self.name, 
        other.name, 
        self.name == other.name))

    return self.name == other.name

Element.__eq__ = eq
elements = [
    Element('a'), 
    Element('b'), 
    Element('c'), 
    Element('d')    
]

print('before {}'.format(elements))
elements.remove(elements[3])
print('after {}'.format(elements))
Run Code Online (Sandbox Code Playgroud)

产生以下输出 -

before [a, b, c, d]
comparing a to d (False)
comparing b to d (False)
comparing c to d (False)
after [a, b, c]
Run Code Online (Sandbox Code Playgroud)

为什么不eq()输出comparing d to d (True) …

python list python-3.x

17
推荐指数
2
解决办法
421
查看次数

如何定义多个需求文件?

如何在我的requirements.txt文件中定义多个需求文件.

-r base.txt
-r test.txt
Run Code Online (Sandbox Code Playgroud)

目前的行为是pip只安装包test.txt.我期望PIP安装在都发现包base.txttest.txt.我本来可以发誓我见过有人这样做,但我找不到任何例子.

python pip python-3.x

11
推荐指数
3
解决办法
3026
查看次数

如何将TypeScript对象转换为普通对象?

我正在使用一个JS库,特别select2是如果我传递的对象不是普通对象,那么它的行为与我想要的不同.这都是通过使用jQuery的isPlainObject函数来检查的.

TypeScript是否有一个我不知道的演员阵容,如果不采用自己编写的话就能做到这一点?

class Opt {
    constructor(public id, public text) {

    }

    toPlainObj(): Object {
        return {
            id: this.id,
            text: this.text
        }
    }
}

let opts = [
    new Opt(0, 'foo'),
    new Opt(1, 'bar')
];

console.clear()

console.log('both should be false')
$.map(opts, opt => {
    console.log($.isPlainObject(opt))
})

console.log('both should be true')
$.map(opts, opt => {
    console.log($.isPlainObject(opt.toPlainObj()))
})
Run Code Online (Sandbox Code Playgroud)

javascript typescript

11
推荐指数
2
解决办法
7653
查看次数

Python可以无缝地执行DI而不依赖于服务定位器吗?

我来自C#世界,所以我的观点可能有些偏差.我想在Python中做DI,但是我注意到了一个趋势,它们都看起来依赖于服务定位器.也就是说,您必须将对象创建绑定到框架,例如injectlib.build(MyClass)为了获取实例MyClass.

这是我的意思的一个例子 -

from injector import Injector, inject


class Inner(object):
    def __init__(self):
        self.foo = 'foo'


class Outer(object):
    @inject(inner=Inner)
    def __init__(self, inner=None):
        if inner is None:
            print('inner not provided')
            self.inner = Inner()
        else:
            print('inner provided')
            self.inner = inner


injector = Injector()

outer = Outer()
print(outer.inner.foo)

outer = injector.get(Outer)
print(outer.inner.foo)
Run Code Online (Sandbox Code Playgroud)

有没有办法在Python中创建一个类,同时根据参数名称自动推断依赖类型?因此,如果我有一个被调用的构造函数参数my_class,那么MyClass将注入一个实例.我问的原因是我没有看到如何将依赖注入到通过第三方库自动创建的类中.

python dependency-injection

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

GCC v4.9.2 上无法识别的命令行选项“-rdynamic”

I\'m using GCC v4.9.2 under Cygwin on Windows 7 64-bit, but running into an issue trying to compile uWSGI.

\n\n

The error I\'m receiving is -

\n\n
gcc: error: unrecognized command line option \xe2\x80\x98-rdynamic\xe2\x80\x99\n
Run Code Online (Sandbox Code Playgroud)\n\n

GCC version output -

\n\n
$ gcc -v\nUsing built-in specs.\nCOLLECT_GCC=gcc\nCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/lto-wrapper.exe\nTarget: x86_64-pc-cygwin\nConfigured with: /cygdrive/i/szsz/tmpp/gcc/gcc-4.9.2-3.x86_64/src/gcc-4.9.2/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-4.9.2-3.x86_64/src/gcc-4.9.2 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/libexec --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --libdir=/usr/lib --datarootdir=/usr/share --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix …
Run Code Online (Sandbox Code Playgroud)

c gcc cygwin uwsgi

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

如何执行在此使用doc的所有脚本参数?

我有一个简单的脚本,称为,可在我的整个代码库中使用sshpass

#!/bin/bash

expect << EOF
spawn $@
expect {
    "*assword" {
        send "$SSHPASS\n"
    }
}
expect eof
EOF
Run Code Online (Sandbox Code Playgroud)

我目前使用此脚本的方式是这样的-

./sshpass scp archive.tgz $SERVER:$DIR
Run Code Online (Sandbox Code Playgroud)

当SSH命令为单行代码时,这非常有效。我的问题是,当我尝试sshpass使用此处文档执行命令时。

./sshpass ssh $user@$server /bin/bash << EOF
    echo "do this..."
    echo "do that..."
    echo "and the other..."
EOF
Run Code Online (Sandbox Code Playgroud)

上面的失败是因为$@仅解析了ssh $user@$server /bin/bash

关于我如何处理SSH身份验证,请不要发表评论。当被迫使用Cygwin时,有些特定的事情(例如密钥身份验证和管理特权)根本无法工作。

bash shell heredoc

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