小编smn*_*brv的帖子

Moment.js:更改默认的humanize()行为

在moment.js文档中,给出了以下示例:

moment.duration(1, "minutes").humanize(); // a minute
moment.duration(2, "minutes").humanize(); // 2 minutes
moment.duration(24, "hours").humanize();  // a day
Run Code Online (Sandbox Code Playgroud)

我需要这个电话

moment.duration(1, "minutes").humanize();
Run Code Online (Sandbox Code Playgroud)

输出“ 1分钟”,我想要这个字符串

moment.duration(24, "hours").humanize();
Run Code Online (Sandbox Code Playgroud)

输出“ 24小时”。

我不能只用1代替“ a”一词,因为它将用于许多不同的语言。

那可能吗?也许一些简单的配置/解决方法/未记录的功能?

javascript momentjs

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

Observable.of转异步

我即将模拟一个包含在observable中的http调用.我最初的想法是简单地使用Observable.of类似的Promise.resolve,但它似乎没有像我预期的那样工作:

Rx.Observable.of('of1').subscribe(e => console.log(e));

console.log('of2');

Rx.Observable.from(Promise.resolve('from1')).subscribe(e => console.log(e));

console.log('from2');
Run Code Online (Sandbox Code Playgroud)
<script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.6/dist/global/Rx.umd.js"></script>
Run Code Online (Sandbox Code Playgroud)

它似乎在异步Observable.of运行时同步Rx.Observable.from(Promise.resolve('from1'))运行(这就是我想要的).只要我想测试微调器显示,同步调用对我来说不是一个选项.

当我延迟它或设置一个计时器时,有某种解决方案:

Rx.Observable.of('of1').delay(0).subscribe...
Run Code Online (Sandbox Code Playgroud)

但这对我来说也不好看.

如何转向Observable.of异步运行?将它从Promise转换似乎是一种矫枉过正.

javascript asynchronous observable rxjs5

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

在 Angular2 中使用无需注入的服务

我是 Angular2 的新手,我有一个类,它在 Angular2 中具有静态函数,我想在其中一个静态函数上实现 http 请求

我有管理表单验证的静态类

FORM VALIDTION
this.userform = this._formbuilder.group({
  first_name: [this.user.first_name, Validators.required],
  last_name: ['', Validators.required],
  username: ['', Validators.compose(
    [
      Validators.required,Validators.minLength(5)
    ]
  )],
  password: ['',Validators.compose([
    Validators.required,ValidationService.passwordValidator
  ])],
  email: ['', Validators.compose([
    Validators.required,ValidationService.emailValidator
  ])],
  role: ['', Validators.required],

})
Run Code Online (Sandbox Code Playgroud)

ValidationService

constructor(private _http:Http){}

 static passwordValidator(control) {
  if(control.value != undefined){
  if (!control.value.match(/^(?=.*[0-9])[a-zA-Z0-9!@#$%^&*]{6,100}$/)) {
    return { 'invalidPassword': true };
  }
 }

 }

static emailValidator(){

return this._http. //this returns an error i would like to 
      //query server to see if email exists

 } …
Run Code Online (Sandbox Code Playgroud)

javascript angular

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

处理插入到选择中的异常

方案1

我有表交易表

create table TXN_HEADER
(
  txn_id         NUMBER(10) not null,
  txn_Date      date 
  product_id    NUMBER(10),
  company_id    NUMBER(10),
  dealer_id     NUMBER(10),
  tran_amt      number(10,2)
)
Run Code Online (Sandbox Code Playgroud)

上表具有对product.product_id 和company.company_id 的外键引用。

该表有 5m 行

模式2

create table TXN_HEADER_REPORTS
(
  txn_id         NUMBER(10) not null,
  txn_Date      date 
  product_id    NUMBER(10),
  company_id    NUMBER(10),
  dealer_id     NUMBER(10),
  tran_amt      number(10,2)
)
Run Code Online (Sandbox Code Playgroud)

这里我们也有相同的约束,具有对product.product_id和company.company_id的外键引用。

在模式 2 中,我们尝试一次性插入从模式 1 到模式 2 的所有行,如下所示

begin 
  insert into TXN_HEADER_REPORTS (
  txn_id, txn_Date ,product_id,company_id   ,  dealer_id ,  tran_amt)
  select 
  txn_id, txn_Date ,product_id,company_id   ,  dealer_id ,  tran_amt
  from schema1.TXN_HEADER;
  commit;
exception   
  when …
Run Code Online (Sandbox Code Playgroud)

oracle plsql insert-into

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

ng build由于regExp而报错

我在常量中有regExp:

export const Constants = {
    QUERY_PARAM_CONFIG: {
        REGEX: /\+/gi,
        REGEX_ENCODED: /%2B/g
    }
};
Run Code Online (Sandbox Code Playgroud)

但是当我运行ng build时出现错误:

ERROR in app\app.module.ts(58,21): Error during template compile of 'AppModule'
  Expression form not supported in 'Constants'
    'Constants' contains the error at app\configuration\constants.ts.
Run Code Online (Sandbox Code Playgroud)

npm构建脚本:

ng build --prod --output-hashing none --sourcemaps=true
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

regex typescript angular-cli angular2-aot angular

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