小编gon*_*250的帖子

在Angular 2中使用*ngFor检查空值的最佳方法

我正在显示来自a的一些记录,api并且一些结果为null,并且我想在响应值为null的情况下显示不同的值.怎么做最好的方法呢?

以下是我的代码:

零件:

import {Component, OnInit} from '@angular/core';
import {PerformancesService} from '../../services/performances.service';
import {Performance} from '../../common/performance';

@Component({
    selector: 'performances',
    templateUrl: './app/components/performances/performances.component.html'
})

export class PerformancesComponent implements OnInit{
    performances: Performance[];

    constructor(private _service : PerformancesService){

    }

    getFunds(){
        this._service.getData().then(
            performances => this.performances = performances
        )
    }

    ngOnInit(){ 
        this.getFunds();
    }
}
Run Code Online (Sandbox Code Playgroud)

模板:

<h2>Performance</h2>

<table class="table table-hover">
  <thead>
      <tr>
          <th>Fund Id</th>
          <th>Country Id</th>
          <th>1Mth</th>
          <th>3Mth</th>
          <th>YTD</th>
          <th>1Yr</th>
          <th>3Yrs</th>
          <th>5Yrs</th>
          <th>10Yrs</th>
      </tr>
  </thead>
  <tbody>
      <tr *ngFor="let performance of performances">
        <td>{{performance.id}}</td>
        <td>{{performance.country_id}}</td>
        <td>{{performance.OneMonthBack}}</td>
        <td>{{performance.ThreeMonthsBack}}</td>
        <td>{{performance.YearToDate}}</td> …
Run Code Online (Sandbox Code Playgroud)

angular

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

打字稿 - 对字符串进行降序排序

我想排序string[]递减的方式.到目前为止,我所做的是以下代码:

let values = ["Saab", "Volvo", "BMW"]; // example 

values.sort();
values.reverse();
Run Code Online (Sandbox Code Playgroud)

它正在工作,但我想弄清楚是否有更好的方法来做到这一点.

arrays typescript

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

如何避免在React中使用setProps?

我正在使用应用程序react & redux,我需要setProps,但它已被弃用.

看看下面的错误:

警告:不推荐使用setProps(...)和replaceProps(...).而是在顶层再次调用渲染.

未捕获的不变违规:setProps(...):您调用setProps了具有父级的组件.这是一种反模式,因为道具在渲染时会被反应性地更新.相反,更改所有者的 render方法以将正确的值作为props传递给创建它的组件.

那我怎么设置道具呢?基本上是管理一些标签,看看我的代码:

export default React.createClass({
  render: function() {
    return (
         <div className="demo-tabs">
             <Tabs activeTab={this.props.activeTab}
                   onChange={(tabId) => this.setProps({ activeTab: tabId })} ripple>
                 <Tab>Stack</Tab>
                 <Tab>GitHub</Tab>
                 <Tab>Twitter</Tab>
             </Tabs>
             <section>
                 <div className="content">Content for the tab: {this.props.activeTab}</div>
             </section>
         </div>
     );
  }
});
Run Code Online (Sandbox Code Playgroud)

容器

import React from 'react';
import TimeLine from './timeline';
import { connect } from 'react-redux';
import { getStackoverflow } from 'api/timeline';

const TimeLineContainer = React.createClass({

    componentWillMount: function() {
      getStackoverflow();
    },

    render: function() …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs redux

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

如何使用代理与 reactjs 建立链接

我在一个网站上工作,前端使用 Reactjs 和 Typescript,后端使用 Java。在开发过程中,我将 3000 端口用于前端,将 8080 端口用于后端。我已经在package.json上设置了代理属性

"proxy": "http://localhost:8080"
Run Code Online (Sandbox Code Playgroud)

所以当我向后端发出请求时我没有任何问题,因为代理工作得很好。

现在我需要创建一些链接来下载报告,所以我正在动态生成链接,我需要它们指向端口8080而不是端口3000

我正在传递网址,如:

<a href={this.state.url}>Download Report</a>
Run Code Online (Sandbox Code Playgroud)

其中this.state.url貌似/报告/下载/用户和有意义其指向的http:// 3000 /报告/下载/用户

知道如何在 dev 中创建指向端口 8080 的链接。

更新

代理正在处理类似于以下代码的请求:

   fetch('./app/admin/reports/availableReports')
    .then(res => res.json())
    .then(json => json.reportTypes)
    .catch(ex => {
        console.log('Alert!!', ex)
        return []
    })
Run Code Online (Sandbox Code Playgroud)

但是当我生成一个 url 链接时它不起作用:

<a href={'app' + this.state.currentDownloadUrl}>Download Report</a>
Run Code Online (Sandbox Code Playgroud)

typescript reactjs react-router

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

为“Create React App”创建的应用添加绝对路径

我通过Create React App创建了一个应用程序,更具体地说,我也在使用打字稿。

我不知道如何设置绝对路径来访问我的组件、页面等。

在不同的情况下,我会用以下内容更新我的 tscongig:

{
    "compilerOptions": {
      "baseUrl": ".",
      "paths": {
        "@components/*": ["src/components/*"]
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

但我不知道如何实现这一点,因为我正在使用react-scripts 任何想法?

typescript reactjs create-react-app

8
推荐指数
2
解决办法
6957
查看次数

在Laravel 4中,php artisan migrate错误PDOException

我有一个问题要执行:

$ php artisan migrate
Run Code Online (Sandbox Code Playgroud)

我收到了一个错误

[PDOException]                             
SQLSTATE[HY000] [2002] Connection refused 
Run Code Online (Sandbox Code Playgroud)

我正在使用MAMP,它工作正常.

我试图将localhost设置为127.0.0.1并且我已添加'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock'但没有任何帮助.

[编辑]我也添加了端口,我已检查用户和密码是否正确,服务器运行正常..任何建议??

谢谢

php mysql laravel

4
推荐指数
2
解决办法
5952
查看次数

Sailsjs - Hook orm需要太长时间才能加载 - 模数

我使用sails.js创建了一个nodejs应用程序.它在我的localhost中完美运行.当我尝试在服务器中发布它时,问题出现在生产中(模数).您可以查看下面的错误.

Error: The hook `pubsub` is taking too long to load.
Make sure it is triggering its `initialize()` callback, or else set `sails.config.pubsub._hookTimeout to a higher value (currently 20000)
    at tooLong [as _onTimeout] (/mnt/data/1/ApiDevConf-master/node_modules/sails/lib/app/private/loadHooks.js:92:21)
    at Timer.listOnTimeout (timers.js:110:15) { [Error: The hook `pubsub` is taking too long to load.
Make sure it is triggering its `initialize()` callback, or else set `sails.config.pubsub._hookTimeout to a higher value (currently 20000)] code: 'E_HOOK_TIMEOUT' }
Run Code Online (Sandbox Code Playgroud)

我试图弄清楚如何解决问题,但没有任何作用.我在这里尝试这样的想法.

我也正确设置了 NODE_ENV = production …

node.js modulus sails.js

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

谷歌地图错误 - Android应用程序|| v2

我正在尝试在Android应用程序上添加地图到我的布局,但我得到以下代码:

06-16 20:51:06.142  17581-17581/wk.gon250.dublinbike E/AndroidRuntime? FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{wk.gon250.dublinbike/wk.gon250.dublinbike.StationDetailsActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2266)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
            at android.app.ActivityThread.access$600(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:5225)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at wk.gon250.dublinbike.StationDetailsActivity.onCreate(StationDetailsActivity.java:38) …
Run Code Online (Sandbox Code Playgroud)

android google-maps android-maps-v2

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

socketio和nodejs,错误404 /socket.io/socket.io.js

我收到此错误"NetworkError:404 Not Found - http://localhost:3000/socket.io/socket.io.js"我不知道如何解决它.我已经尝试更改端口,添加端口链接......我不知道.

我的app.js:

var express = require('express')
  , http = require('http')
  , stylus = require('stylus')
  , nib = require('nib')


var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);


function compile(str, path) {
  return stylus(str)
    .set('filename', path)
    .use(nib());
}

app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.use(express.logger('dev'))
app.use(stylus.middleware(
  { src: __dirname + '/public'
  , compile: compile
  }
))
app.use(express.static(__dirname + '/public'))

app.get('/', function (req, res) {
  res.render('index',
  { title : 'Home' }
  ) …
Run Code Online (Sandbox Code Playgroud)

node.js express socket.io pug

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

打字稿 - 排序通用数组

我正在尝试实现一个函数,typescript用户可以在其中传递一个array对象和一个对象的属性,并通过用户选择的属性返回列表顺序.

function OrderByArray(values: any[], orderType: any) { 
    //TODO: implement code
    return values;
} 
Run Code Online (Sandbox Code Playgroud)

有办法吗?我知道如何对数组进行排序,但我不知道如何允许通过它发送typeof对象和顺序.

谢谢!

arrays typescript typescript-typings typescript2.0

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