小编U r*_*ock的帖子

如何从角度2中的文本中删除html标记

我正在使用rss feed并从我的服务器获取rss feed所以我发送了stringfy数据,但是当我在我的angular 2应用程序中绑定它时,它显示带有html标签的文本,以便我们如何删除此标签.我只是想显示文字.

这是服务器代码:

exports.newspage=function(req,resp){
db.executeSql("select header,text,teaser from news_d",function(data,err){
        if(err){
            resp.writeHead(200,{"Content-Type":"text/html"});
            resp.write("<html><head><title>500</title></head></html>");
        }
        else{
            resp.writeHead(200,{"Content-Type":"x-application/json"});
            resp.write(JSON.stringify(data));
        }
        resp.end();
    });
};

app.get('/newspage', function(req, resp) {

    emp.newspage(req,resp);

});
Run Code Online (Sandbox Code Playgroud)

service.ts:

gettagesnews(){
     let headers = new Headers();
       headers.append('x-access-token',this.token);
         var options = new RequestOptions({headers: headers});
      return this.http.get('http://services.com:9000/newspage/',options).map((res:Response) => res.json())
    .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
  }
Run Code Online (Sandbox Code Playgroud)

news.ts:

tagesnews:Array<TagesnewsList>;

this.newsauth.gettagesnews().subscribe((dailynews)=>{
    this.tagesnews=dailynews;
  });
Run Code Online (Sandbox Code Playgroud)

HTML:

<div *ngFor="let daily of tagesnews">
       <span style="font-size: 13px">{{daily.text}}</span> </button>
    </div>
Run Code Online (Sandbox Code Playgroud)

我得到了一些回复 :

示范文本

javascript node.js angular

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

离子段按钮带有图标和文字,使标签栏

我尝试使用图标和文本来实现离子段按钮,如标签栏,但有所不同.到目前为止我尝试过的

<ion-footer>
  <ion-segment style="background:#3B6593">
    <ion-segment-button style="color:white">
      <ion-icon name="home"></ion-icon>
      Heizöl
    </ion-segment-button>
    <ion-segment-button value="diesel_10" style=color:white>
      <ion-icon name="home"></ion-icon>
      Diesel
    </ion-segment-button>
    <ion-segment-button value="benzin_e5" style=color:white>
      <ion-icon name="home"></ion-icon>
      Benzin E5
    </ion-segment-button>
    <ion-segment-button value="benzin_e10" style=color:white>
      <ion-icon name="home"></ion-icon>
      Benzin E10
    </ion-segment-button>
    <ion-segment-button value="benzin_e10" style=color:white>
      <ion-icon name="home"></ion-icon>
      Benzin E10
    </ion-segment-button>
  </ion-segment>
</ion-footer>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我试着用这样的超级标签来获取它

<ion-footer>
    <super-tabs toolbarColor="light">
        <super-tab [root]="tab1Root" title="Home" icon="home"></super-tab>
        <super-tab [root]="tab2Root" title="Uneverasalseite" icon="ios-globe"></super-tab>
        <super-tab [root]="tab3Root" title="News" icon="logo-designernews"></super-tab>
        <super-tab [root]="tab4Root" title="Tickcharts" icon="ios-stats"></super-tab>
        <super-tab [root]="tab5Root" title="RPI" icon="ios-pulse"></super-tab>
      </super-tabs>
</ion-footer>
Run Code Online (Sandbox Code Playgroud)

结果将是

在此输入图像描述

但在这里我需要设计风格,很难减少标签栏高度和调整文字大小.

ionic3

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

单击事件原生元素(锚标记)的单元测试

我有简单的锚标记和一些网址。测试的目标是当单击链接时,它应该在新选项卡中打开,然后将给定的 url 与打开的新选项卡 url 进行比较。

我尝试过使用间谍On 和窗口对象。但我没有成功。

这是我尝试过的。

<a href="https://www.google.com/" target="_blank">google</a>


import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('guideline link', () => {
    let comp: AppComponent;
    let fixture: ComponentFixture<AppComponent>;

    beforeEach(() => {
        TestBed.configureTestingModule({
            imports: [],
            declarations: [AppComponent],
            providers: [],
        });

        fixture = TestBed.createComponent(AppComponent);

        comp = fixture.componentInstance;
    });

    it('link should be opened in separate tab', async () => {
        fixture.detectChanges();
        spyOn(window, 'open');
        const link = fixture.debugElement.nativeElement.querySelector('a');
        fixture.whenStable().then(() => {
            expect(link).toHaveBeenCalled();
            expect(window.open).toHaveBeenCalledWith('https://www.google.com/');
        });

    });

});
Run Code Online (Sandbox Code Playgroud)

unit-testing karma-jasmine angular

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

当某些键为数字键时,无法按对象键对数据进行排序

我有对象包含这样的数据

const testData = {
        "11": {
            "data": {
                "firstName": "firstName",
                "lastName": "lastName"
            }
        },
        "12": {
            "data": {
                "firstName": "firstName",
                "lastName": "lastName"
            }
        },
        "00": {
            "data": {
                "firstName": "firstName",
                "lastName": "lastName"
            }
        },
        "01": {
            "data": {
                "firstName": "firstName",
                "lastName": "lastName"
            }
        },
        "final": {
            "data": {
                "firstName": "firstName",
                "lastName": "lastName"
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我想按对象键对数据进行排序 00, 01, 11, 12, final

我已经尝试过这种方法,但是我无法达到我想要的效果。任何想法都会感激不尽?

sorted = Object.keys(testData).sort().reduce((acc, key) => ({
  ...acc, [key]: testData[key]
  }), {})

console.log(sorted)
Run Code Online (Sandbox Code Playgroud)

javascript object

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

将数字字符串转换为角度2的数字

我想比较角度2表达式.我从我的数据库中获取数字字符串中的数据数组我需要将其转换为数字,然后使用ngClass进行样式设置.我怎么能转换这种类型.任何的想法?

  <td [ngClass]= "{'positive': gbh.Last > 0, 'negative': gbh.Last < 0}"> {{gbh.Last}} </td>
Run Code Online (Sandbox Code Playgroud)

javascript angular

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