我尝试Unauthorized使用redux-saga 处理来自服务器的错误.这是我的传奇:
function* logIn(action) {
  try {
    const user = yield call(Api.logIn, action);
    yield put({type: types.LOG_IN_SUCCEEDED, user});
  } catch (error) {
    yield put({type: types.LOG_IN_FAILED, error});
  }
}
Run Code Online (Sandbox Code Playgroud)
我获取这样的数据:
fetchUser(action) {
  const {username, password} = action.user;
  const body = {username, password};
  return fetch(LOGIN_URL, {
    method,
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(body)
  })
    .then(res => {
      res.json().then(json => {
        if (res.status >= 200 && res.status < 300) {
          return json
        } else {
          throw res
        }
      }) …Run Code Online (Sandbox Code Playgroud) 我用这个例子写了Crowdsale .但我无法发送事务,我的测试失败并出现错误:
 Contract: Crowdsale should accept payments after start:
     AssertionError: expected promise to be fulfilled but it was rejected with 'Error: VM Exception while processing the transaction: revert'
Run Code Online (Sandbox Code Playgroud)
我试图将汽油价格设置为这样的交易,crowdsale.sendTransaction({value, from: buyer, gas: 4712388})但它对我没有帮助.
我的众筹:
pragma solidity ^0.4.16;
interface token {
  function transfer(address receiver, uint amount) external;
}
contract Crowdsale {
  address public beneficiary;
  uint public fundingGoal;
  uint public amountRaised;
  uint public deadline;
  uint public price;
  token public tokenReward;
  mapping(address => uint256) public balanceOf;
  event FundTransfer(address backer, …Run Code Online (Sandbox Code Playgroud) 为什么 {} == {} 和 {} === {} 在 javascript 中是假的?
{} == {} // false
{} === {} // false
Run Code Online (Sandbox Code Playgroud) 我有一个简单的组件来处理粘贴事件到表单输入中。
表格:
this.searchForm = this.formBuilder.group({
  query: [ null, [Validators.required] ]
});
onPaste(event) {
    event.preventDefault();
    const formattedQuery = event.clipboardData.getData('text/plain')
      .split(/,?[\r\n\t]+\s?/)
      .join(', ')
      .replace(/,\s?$/g, '');
    this.searchForm.get('query').setValue(formattedQuery);
  }
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试测试它,它看起来像这样:
it('should reformat pasted data', () => {
    const queryField = fixture.debugElement.query(By.css('input[type="search"]'));
    queryField.nativeElement.dispatchEvent(new ClipboardEvent('paste', {
      dataType: 'text/plain', 
      data: '123\r123'
    }));
    fixture.detectChanges();
    expect(queryField.nativeElement.value).toBe('123, 123');
    // also tried expect(component.searchForm.get('query').value).toBe('123, 123');
  });
Run Code Online (Sandbox Code Playgroud)
但结果我有
Expected '' to be '123, 123'
Run Code Online (Sandbox Code Playgroud)
如果我这样做,console.log(queryField.nativeElement)它会显示输入,但为什么它不处理new ClipboardEvent('paste')事件?
<input class="ng-untouched ng-pristine ng-invalid" formcontrolname="query" type="search" ng-reflect-name="query">
Run Code Online (Sandbox Code Playgroud)
您可以在这里找到完整的组件https://stackblitz.com/edit/angular-cp9yhx?file=app%2Fhello.component.ts
我的单元测试有什么问题?
我正在尝试使用Karma-Jasmine测试我的Angular服务,我需要确保在服务初始化后loadApp调用了函数.测试它的最佳方法是什么?
import { Injectable, NgZone } from '@angular/core';
@Injectable()
export class GdlService {
  appName = 'myAppName';
  constructor(
    private ngZone: NgZone,
  ) {
    this.ngZone = ngZone;
    this.loadApp(this.appName);
  }
  private loadApp(appName) {
    this.ngZone.runOutsideAngular(() => {
      // ...some logic
    });
  }
}
Run Code Online (Sandbox Code Playgroud) 我有一个用于2个模板的用户组件.用户表的第一个模板,用户页面的第二个模板.我选择按role属性使用的模板.
第一个使用示例:
<table>
    <tr user *ngFor="let user of users" [user]="user" role="UserTableItem"></tr>
</table>
Run Code Online (Sandbox Code Playgroud)
在另一个模板中,我使用我的组件,如下所示:
<div user [user]="user" role="UserCard"></div>
Run Code Online (Sandbox Code Playgroud)
那么,我的user组件模板:
// user.template.html
<user-card [user]="user" *ngIf="role === 'UserCard'"></user-card>
<user-list-item [user]="user" *ngIf="role === 'UserListItem'"></user-list-item>
Run Code Online (Sandbox Code Playgroud)
我们可以看到,这里有两个组件user-card和user-list-item.user-card包含div块,user-list-item包含td块.并且表崩溃了,因为我有一个<user-list-item>块,我的表看起来像:
<table>
   <tr>
     <user-list-item>
       <td></td>
       <td></td>
     </user-list-item>
   </tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决我的问题并获得这样的表格?
<table>
   <tr>
     <td></td>
     <td></td>
   </tr>
</table>
Run Code Online (Sandbox Code Playgroud)
UPD:
我的user组件:
// user.component.ts
import { Component, Input, Inject, Attribute } from '@angular/core';
import …Run Code Online (Sandbox Code Playgroud) 我使用redux-saga并创建了一个checkUsername执行API调用的生成器.我虽然这const username等于来自API的响应,但我已经得到了undefined.
function* checkUsername(action) {
  try {
    const username = yield call(Api.checkUsername, action.username);
    yield put({type: actions.USERNAME_CHECK_SUCCEEDED, username});
  } catch (e) {
    yield put({type: actions.USERNAME_CHECK_FAILED, message: e.message});
  }
}
Run Code Online (Sandbox Code Playgroud)
虽然在我的checkUsername函数中,哪个调用API res是相同的{"isExist": false}:
 checkUsername(username) {
    fetch(url, {
    'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(response => response.json())
      .then(res => res)
      .catch(error => console.error(error));
 },
Run Code Online (Sandbox Code Playgroud)
为什么我const username不平等{"isExist": false}?
我pandas.Series.value_counts用来计算用户的性别.但是我还需要获得结果的关键点来绘制绘图并使用键作为绘图的标签.
例如,结果data.gender.value_counts()是:
female     6700
male       6194
brand      5942
unknown    1117
Run Code Online (Sandbox Code Playgroud)
我还需要获得一份清单['female', 'male', 'brand', 'unknown']并保留订单.
我怎样才能做到这一点?
我创建了一个图像视图组件,其中包含旋转、放大和缩小按钮。当您单击按钮时,它会将 CSS 添加transform到图像中。
由于某种原因,当我缩放图像时,我无法将其滚动到最顶部或最左边的角落。我尝试添加transform-origin: top left;到图像中,它修复了缩放,但是,它破坏了旋转。我该如何解决这个问题?
您可以在这里看到我的代码https://codesandbox.io/s/delicate-star-eitj3s?file=/src/app/app.component.ts
编辑:
transform-origin: top left;使图像粘在左上角,但我需要将图像保持在中心。是否可以修复滚动并将图像变换的原点保持在中心?
有人告诉我:"声明接近其使用的变量具有价值".他纠正了我:
void student_score(size_t student_list_size) {
  // int exam;
  // int average;
  // int digit;
  // int counter_digits;
  for (size_t i = 0; i < student_list_size; i++) {
    int exam;
    int average;
    int digit;
    int counter_digits;
Run Code Online (Sandbox Code Playgroud)
我认为这很糟糕,因为这里变量初始化了每个循环.什么是真的?
javascript ×6
angular ×3
karma-runner ×2
redux ×2
redux-saga ×2
angularjs ×1
c ×1
c++ ×1
css ×1
ethereum ×1
fetch ×1
pandas ×1
python ×1
react-native ×1
reactjs ×1
solidity ×1
truffle ×1
typescript ×1