小编mes*_*lds的帖子

JavaScript:在Array Literal中访问自己的Object属性

给定JavaScript对象中的Array Literal,访问其自己的对象的属性似乎不起作用:

 var closure =  {

         myPic : document.getElementById('pic1'),
         picArray: [this.myPic]
 }    

 alert(closure.picArray[0]); // alerts [undefined]
Run Code Online (Sandbox Code Playgroud)


而通过访问其他JavaScript对象来声明一个数组项似乎有效

 ?var closure1 = {
 ?    
 ?     myPic : document.getElementById('pic1')
 ?}
 ?    
 ?var closure2 =  {
 ?  
 ?        picArray: [closure1.myPic]
 ?}    
 ?    
 ?alert(closure2.picArray[0]); // alerts [object HTMLDivElement]
Run Code Online (Sandbox Code Playgroud)


示例:http: //jsfiddle.net/5pmDG/

javascript arrays oop unobtrusive-javascript

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

如何在模板中使用注入的服务(Angular2)

零件

templateUrl : 'home.html'
..
providers:      [NavService]
..    
private navService:     NavService,
..
Run Code Online (Sandbox Code Playgroud)

模板

 <li *ngFor="let state of states; let i=index" 
[class.active]="navService.isCurrentState(state)">

<span class="name">{{navService[state].name}}</span>
Run Code Online (Sandbox Code Playgroud)

似乎不起作用,我在这里缺少什么?如何在组件模板中访问我的服务?

angular

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

Fs-Extra 只能删除目录中的文件吗?

我可以删除 apples 目录中的所有文件而不删除目录本身吗?fs-extra API没有描述是否可能。

 fsExtra.remove 'apples/*', ->
    if !err
    # Do stuff
Run Code Online (Sandbox Code Playgroud)

node.js fs-extra

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

Angular2:"TypeError:无法读取未定义的属性'createAsync'"

单元测试

import {Goal} from '../../providers/goal/goal';
import {GoalSettingsPage} from './goal-settings';

import {Modal, Alert, NavParams, ViewController, Events} from 'ionic-angular';
import {provide,ReflectiveInjector,Component} from '@angular/core'
import {FormBuilder} from '@angular/common';

import {
  beforeEach,
  beforeEachProviders,
  describe,
  expect,
  it,
  xit, 
  TestComponentBuilder, 
  ComponentFixture, 
  inject,
  async
} from '@angular/core/testing';


describe('Goal Settings', () => {

    it('should display header title: "Some Title"', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
        return tcb.createAsync(GoalSettingsPage).then((fixture) => {
            fixture.detectChanges();

            var compiled = fixture.debugElement.nativeElement;

            expect(compiled.innerHTML).toContain('ion-title');               
            expect(compiled.querySelector('span'))        .toHaveText('Cancel');
            expect(compiled.querySelector('ion-title')    .innerText).toBe('DrEvil');

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

错误消息

TypeError:无法读取未定义的属性"createAsync"

问题

Pascal在这里写道:http://5thingsangular.github.io/2016/04/11/issue-1.htmlinjectAsync被弃用,所以我如何 …

unit-testing karma-jasmine angular

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

TypeError:无法在Angular2 Observable中读取null的属性"next"

错误

TypeError:无法读取null的属性"next"

模板调用Observer.next(问题)

import { NavService } from '../../providers/services/nav-service/nav-service';

@Component({
  selector: 'ion-header',
  providers: [NavService],
  template: `
    <ion-navbar>
        <ion-title>{{navService.getCurrentName()}}</ion-title>
        <ion-buttons start>
            <button (click)="navService.goHome()">
                <span primary showWhen="ios">Cancel</span>
                <ion-icon name="md-close" showWhen="android,windows"></ion-icon>
            </button>
        </ion-buttons>
    </ion-navbar>
  `
})
Run Code Online (Sandbox Code Playgroud)

有Observable的服务

import { Platform } from 'ionic-angular';
import { Observable } from 'rxjs/Observable';
import { Injectable, ViewChild } from '@angular/core'

@Injectable()

export class NavService {
private dismissObserver: any
public  dismiss: any

constructor (
    private authService:    AuthService,
    private platform:       Platform
) {
    this.dismissObserver = null;
    this.dismiss = Observable.create(observer …
Run Code Online (Sandbox Code Playgroud)

typescript ionic2 angular

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

Hadoop:连接到主机本地主机端口 22:运行 start-dfs.sh 时连接被拒绝

使用最新的 (Okt 2014) Hadoop 启动时,start-dfs.sh我们看到:

连接到主机本地主机端口 22:运行时连接被拒绝

hadoop

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

Angular2:通过指令将外部Component注入其他组件无效

我希望子组件模板加载到父组件模板中.(由于缺乏更好的措辞,我称之为孩子和父母)

这是我的孩子:

import {Component,Directive, ElementRef, Input} from '@angular/core';
import {IONIC_DIRECTIVES} from 'ionic-angular';


@Component({ 
  selector: '[parentselector]',
  template: '<div>I AM A CHILD</div>',
  directives: [IONIC_DIRECTIVES] 
})


export class ChildPage {
    constructor() {

    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的父母:

@Component({
    templateUrl: 'build/pages/parent/parent.html',
    directives: [ChildPage]
})
Run Code Online (Sandbox Code Playgroud)

和父母的HTML:

<ion-content>
    <ion-slides>
        <ion-slide><parentselector>Parent To Be Overriden</parentselector>
        </ion-slide>
    </ion-slides>
</ion-content>
Run Code Online (Sandbox Code Playgroud)

有什么想法错了吗?

typescript ionic-framework ionic2 angular

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

将angular2组件名称/"this"转换为String

在Angular2组件中,执行时:

console.log (this);
Run Code Online (Sandbox Code Playgroud)

你可以按预期获得所有成员的整个对象,例如

"ComponentName {member1, member2, member_n}"
Run Code Online (Sandbox Code Playgroud)

现在我只想记录ComponentName.怎么实现?

typescript angular

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

无法绑定到颜色,因为它不是“按钮”的已知属性

错误

Can't bind to color since it isn't a known property of 'button'.
Run Code Online (Sandbox Code Playgroud)

代码

@Component({
    selector: "nav-next",
    template: `
    <div class="nav-next-directive">
        <button [color]="color" class="primary" [
        </button>
    </div>`
})
Run Code Online (Sandbox Code Playgroud)

预期行为

这个子指令使我们能够在 Angular2-RC4 中从父组件动态设置颜色。Angular2-Final 说这不好。有任何想法吗?

angular

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

Selenium 围绕“TimeoutException”的工作未定义?

我想解决Python Selenium 中的TimeOutException

有时候是这样的:

1.) Open Browser, Call URL
2.) Trying to find Element
2.1) Works sometimes
2.2) Works not sometimes and throws TimeoutException
3.) Should look for other elements
Run Code Online (Sandbox Code Playgroud)

3.)在我们遇到异常2.2)并且 try/catch 不起作用之后,我永远无法到达步骤。

步骤之后3.)还有许多其他步骤。我怎样才能让程序在这个超时时间内运行。当元素不存在时,就会超时。

代码

1.) Open Browser, Call URL
2.) Trying to find Element
2.1) Works sometimes
2.2) Works not sometimes and throws TimeoutException
3.) Should look for other elements
Run Code Online (Sandbox Code Playgroud)

结果

    def getByClass(InputElement, driver):
        getByClass = WebDriverWait(driver, timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, InputElement)))
        return getByClass …
Run Code Online (Sandbox Code Playgroud)

python selenium

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