小编Sle*_*er9的帖子

Angular2'this'未定义

我有一个代码如下:

export class CRListComponent extends ListComponent<CR> implements OnInit {

    constructor(
        private router: Router,
        private crService: CRService) {
        super();
    }

    ngOnInit():any {
        this.getCount(new Object(), this.crService.getCount);
    }
Run Code Online (Sandbox Code Playgroud)

ListComponent代码是这样的

@Component({})
export abstract class ListComponent<T extends Listable> {

    protected getCount(event: any, countFunction: Function){
        let filters = this.parseFilters(event.filters);
        countFunction(filters)
            .subscribe(
                count => {
                    this.totalItems = count;
                },
                error => console.log(error)
            );
    }
Run Code Online (Sandbox Code Playgroud)

CRService的相应服务代码片段是这样的:

getCount(filters) {
    var queryParams = JSON.stringify(
        {
            c : 'true',
            q : filters
        }
    );

    return this.createQuery(queryParams)
        .map(res => res.json())
        .catch(this.handleError);
} …
Run Code Online (Sandbox Code Playgroud)

javascript angular2-services angular

7
推荐指数
1
解决办法
8115
查看次数

MPAndroidChart RadarChart自行崩溃

我有一些RadarChart标签问题.具体来说,如果我使用长文本(例如15-20个字符),并且可用空间不是太大,则图表会折叠并且标签位于折叠图表内(但显然有更多可用空间).

我试图用ValueFormatter标签轴截断标签,如果长度超过5个字符,但正如我所见,图表大小计算基于完整标签文本,因为图表折叠方式与我之前描述的相同.

XAxis xAxis = radarChart.getXAxis();
xAxis.setValueFormatter(new XAxisValueFormatter() {
    @Override
    public String getXValue(String original, int index, ViewPortHandler viewPortHandler) {
        return original.length() > 5 ? original.substring(0, 5) + "…" : original;
    }
});
Run Code Online (Sandbox Code Playgroud)

这里有一些图片来澄清问题.图表显示在CardViews 内部,正如您所看到的,所有侧面都有足够的空间.前两张图片是用ValueFormatter套装拍的,后两张是没有它的.

描述

描述

描述

描述

android radar-chart mpandroidchart

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

Apache DateUtils截断WEEK

我正在使用Apache commons-lang3 DateUtils.truncate(Calendar calendar, int field)方法来"切断"Calendar对象的不必要字段.现在当field参数获得值时Calendar.WEEK_OF_MONTH,它会抛出一个

java.lang.IllegalArgumentException: The field 4 is not supported

truncate()方法的文档说:

/**
 * <p>Truncates a date, leaving the field specified as the most
 * significant field.</p>
 *
 * <p>For example, if you had the date-time of 28 Mar 2002
 * 13:45:01.231, if you passed with HOUR, it would return 28 Mar
 * 2002 13:00:00.000.  If this was passed with MONTH, it would
 * return 1 Mar 2002 0:00:00.000.</p>
 * …
Run Code Online (Sandbox Code Playgroud)

java apache-commons-lang apache-commons-dateutils

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

ViewPager中的ScrollView不会在Android 4.x上滚动

我有一个问题,似乎只影响Android 4.x版本,也可能是设备特定的(即我的华为G630@4.3上不存在,但确实存在于Samsung Ace2@4.4.4上).我有一个ScrollView包含RelativeLayout4 CardView秒的.现在在一些4.x设备上,当我尝试从卡片开始滚动时,滚动事件根本不会发生.如果我触摸卡之间的小填充或第一张卡之上(而不是任何两张之间)和设备屏幕,我可以滚动内容.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/tools"
                    xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="@dimen/activity_horizontal_margin">

        <android.support.v7.widget.CardView
            android:id="@+id/metricsContainerCard"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            app:cardElevation="2dp"
            card_view:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="10dp">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center_vertical"
                        android:layout_marginRight="5dp"
                        android:src="@drawable/metrics"/>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/metrics"
                        android:textSize="20sp"/>
                </LinearLayout>


                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/projectCircleBackgroundShadow"/>

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/warningsContainerCard"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_below="@id/metricsContainerCard"
            app:cardElevation="2dp"
            card_view:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="10dp">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:layout_width="20dp" …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview android-4.2-jelly-bean

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

同一台服务器上的Spring Boot + Angular2

我在本教程之后成功地将我的Angular2应用程序与Spring Boot后端集成,将已编译的JS资源放到/ ui子目录中.基本上一切正常,Angular2应用程序可以通过appname/ui URL访问.

但是,我想知道是否有办法告诉Spring'传递' / ui路径的子网,因为当前Spring拦截了每个请求目标/ ui/*,阻止Angular2路由器正确导航到/ ui路径下的资源.

目前,我只在我的一个控制器中有这个映射:

@RequestMapping(value = "/ui")
public String uiIndex() {
    return "/ui/index.html";
}
Run Code Online (Sandbox Code Playgroud)

有了这个,接口正确地显示在/ ui,但是当我直接从浏览器中解决,Spring会向我发送错误和404 .Angular2应用程序内部的路由器导航工作正常.

编辑

我正在使用此配置将已编译的Angular2资源从target/ui添加到static/ui文件夹(我的项目使用maven构建):

        <resource>
            <directory>${project.basedir}/src/main/resources</directory>
            <includes>
                <include>*.properties</include>
                <include>templates/*.*</include>
            </includes>
        </resource>
        <resource>
            <directory>target/ui</directory>
            <targetPath>static/ui</targetPath>
        </resource>
Run Code Online (Sandbox Code Playgroud)

要明确的是,唯一的问题是,当我在浏览器中输入像/ ui/home/settings这样的URL时,Spring会拦截请求并抛出错误.我可以愉快地导航到/ ui,然后导航到Angular上下文中的/ home/settings.

java spring spring-boot angular

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