小编Dil*_*umN的帖子

如何将不可变的js导入角度2(alpha)?

我试过了:

import {Component, Template, bootstrap} from 'angular2/angular2';
import {Immutable} from 'immutable/immutable';

@Component({
  selector: 'my-app'
})
@Template({
  inline: '<h1>Hello {{ name }}</h1>'
})

class MyAppComponent {
  constructor() {
    this.name = 'Alice';
    this.wishes = Immutable.List(['a dog', 'a balloon', 'and so much more']);
    console.log(this.wishes);
  }
}

bootstrap(MyAppComponent);
Run Code Online (Sandbox Code Playgroud)

但是然后Immutable最终被定义为未定义.然后我尝试了:

import {Component, Template, bootstrap} from 'angular2/angular2';
import {Immutable} from 'immutable/immutable';

@Component({
  selector: 'my-app'
})
@Template({
  inline: '<h1>Hello {{ name }}</h1>'
})

class MyAppComponent {
  constructor(im: Immutable) {
    this.name = 'Alice';
    this.wishes = im.List(['a dog', 'a …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 immutable.js angular

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

(Angular2)无法读取toastr的undefined属性'extend'

我正在尝试在angularjs 2中使用toastr作为服务,将在我的组件中注入,如下所述.当调用handleEvent函数时,我正在接收"无法读取未定义的属性'扩展'".非常感谢对错误的任何建议和/或解释.

app.moudle.ts已导入ToastrService,并且已在提供程序中添加ToastrService.

//events/events-list.components.ts

import { ToastrService } from '../common/toastr.service';
@Component ({
    selector: 'event-list',
    template: `
    <div>
        <h1> Upcoming Angular 2 Event </h1>
        <hr>
        <div class="row">
            <div *ngFor="let event_data of all_data" class="col-md-5">
                <event-thumbnail (click)="handleEvent(event_data.name)" [event]="event_data"></event-thumbnail>
    </div>  
            </div>
        </div>
    `
})

export class EventListComponent implements OnInit {
  all_data:any[]
  constructor(private eventService : EventService , private toastr : ToastrService ){
    //moved code from here to ngOnInit 
  }

  ngOnInit(){
    this.all_data = this.eventService.getEvents();
  }

  handleEvent(eventName) {
    console.log("hey here  "+eventName);
    this.toastr.success(eventName);
  }
}
Run Code Online (Sandbox Code Playgroud)

错误:
[在console.log输出后抛出此错误]

EXCEPTION:./ …

javascript typescript toastr angular

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

将单独的.sqlite文件添加到ios项目

我从SQLite Manager firefox插件创建了一个myDB.sqlite数据库.我想将myDB.sqlite文件添加到我的项目中.然后我可以编写函数来从表中获取数据.

我尝试将myDB.sqlite文件添加到项目文件夹并创建这样的文件路径.但我认为这个文件路径是错误的.

-(NSString *) filePath{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"document.sqlite"];
    return path;
}
Run Code Online (Sandbox Code Playgroud)

将myDB.sqlite文件添加到项目文件夹中是否正确?或者我应该在哪里保存这个myDB.sqlite文件以及我应该使用的文件路径是什么?

sqlite iphone ios

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

来自Afnetworking的大图像缓存

我正在使用AFNetworking将一些图像从互联网下载到我的应用程序.我正在使用此代码下载这些图片,

AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_linkString[indexPath.item]]]];
requestOperation.responseSerializer = [AFImageResponseSerializer serializer];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
    _imageView.image = responseObject;

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Image error: %@", error);
    }];

[requestOperation start]; 
Run Code Online (Sandbox Code Playgroud)

我注意到所有响应映像都是从此方法自动缓存到磁盘的.我的应用程序中也有这个选项.所有缓存的图像大小约为150kb.但是当我下载大约2MB大小的图像时,这些图像不会自动缓存到磁盘.

为什么小尺寸图像被缓存而大尺寸图像没有被缓存?我是否使用错误的方法在AFNetworking中缓存图像?

任何人都可以使用AFNetworking为我提供缓存2MB图像的解决方案....

谢谢

iphone caching objective-c ios afnetworking

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

如何使用EPPlus for A4纸张创建Excel文件

我当前的项目使用EPPlus来创建Excel文件.这些文件由用户打印,我试图强制Excel文件只在一个A4页面打印,无论宽度和内容如何.

实际上,当打印文件时,它需要两页,而第二页只包含一列.

我的代码:

ws.PrinterSettings.Orientation = eOrientation.Landscape;
ws.PrinterSettings.PrintArea = ws.Cells[ws_dimension_adress];
ws.PrinterSettings.TopMargin= 0;
ws.PrinterSettings.RightMargin = 0;
ws.PrinterSettings.BottomMargin = 0;
ws.PrinterSettings.LeftMargin = 0;
ws.Cells[ws_dimension_adress].AutoFitColumns();
ws.Cells[ws_dimension_adress].Style.Font.Size = 9;
Run Code Online (Sandbox Code Playgroud)

结果:我的代码提供的结果

在此输入图像描述

我需要的:

在此输入图像描述

我搜索了"autofit to A4 page"之类的内容,但是还没有解决方案.

备注:需要所有列.在创建文件之前,我不能简单地删除一个.

谢谢你的帮助!

c# printing asp.net excel epplus

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

Angular 2+ - 根据路线改变css

我正在尝试在Angular中构建一个选项卡菜单(v2.4.5).根据路线激活选项卡.

例如,我有这样的路线:

const routes: Routes = [
  {
    path: 'tab1',
    component: Tab1Component,
  },
  {
    path: 'tab2',
    component: Tab2Component,
  }
];
Run Code Online (Sandbox Code Playgroud)

如果用户输入http://localhost/tab2我想要tab2突出显示的地址(更改选项卡css).

实现这一目标的最佳方法是什么?

css angular

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

使用RxSwift重新加载Tableview

我正在使用RxSwift进行tableview.每次从api获取数据后我都需要重新加载我的表但是我没有这样做.我找不到任何解决方案.有人可以帮忙吗?

我有一个从Api的响应获得的地方数组.我在视图中使用了这个代码加载,但是在更新数组时它没有被调用.

在此输入图像描述

ios swift rx-swift rx-cocoa

3
推荐指数
2
解决办法
8761
查看次数

将标题图像连接到导航栏

所以我的导航栏顶部溢出了其他任何东西.我希望我的标题图像连接到它下面但滚动时不跟随导航栏,只是保持原样.这是一张图片,展示我正在处理的事情:

在此输入图像描述

我想消除导航栏和标题之间的空格.

这是我的css:

.wrapper {
    width: 100%;
    overflow: hidden;

}
.container {
    width: 100%;
    margin: 0 auto;
}
.banner-img {
    width: 100%;
}
Run Code Online (Sandbox Code Playgroud)

这是我的HTML:

  <div id="wrapper">
    <div id="container">
        <a><img class="banner-img" src="images/banner.png"/>
    </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

我的导航栏:

CSS:

ul.nav {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
    position: fixed;
    top: 0;
    width: 100%;
}

ul.nav-right {
    float:right;
    list-style-type:none;
}

li.nav {
    float: left; /* Slides each element next to each other */
}

li.nav a {
    display: block;
    color: white; …
Run Code Online (Sandbox Code Playgroud)

html css

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

如何等待渲染组件直到在 Angular 2 中收集所有数据

我尝试了很多方法让 ngModel 在我的编辑页面中工作,但它给了我一个错误。发生错误是因为 ngModel 在加载之前尝试获取数据。请参阅下面的我的代码。

产品编辑组件

import 'rxjs/add/operator/switchMap';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { Location } from '@angular/common';

import { Product } from './../shared/product.model';
import { ProductService } from './../shared/product.service';

@Component({
    selector: 'product-edit',
    template: require('./product-edit.component.html'),
    providers: [ProductService]
})

export class ProductEditComponent implements OnInit {
    product: Product;
    name2: boolean = false;

    constructor(
        private productService: ProductService,
        private route: ActivatedRoute,
        private location: Location,
        private router: Router
    ) { }

    ngOnInit(): void { …
Run Code Online (Sandbox Code Playgroud)

asynchronous typescript angular

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

Angular 2 @HostListener未捕获keyup事件

我有一个应该捕获键入事件的Google地图。我的组件是google maps div的父级。它可以在Chrome上正常运行,不能在Firefox或IE(未经测试的wtith Edge)上运行。

我的组件:

@Component({
  selector: 'dashboard',
  templateUrl: 'dashboard.component.html',
  styleUrls:  ['dashboard.component.css'],
  host: {
    '[attr.tabindex]': '-1'
  },
  providers: []
})
export class DashboardComponent implements OnInit{

  /* some functions and other stuff here 
  * ...
  */

  @HostListener('keyup', ['$event']) keyup(e) {
    console.log('This will be called with Chrome, not with the others.');
  }
};
Run Code Online (Sandbox Code Playgroud)

你经历过同样的经历吗?(如果需要更多信息,请告诉我)。谢谢

[edit]
我尝试keyup通过使用ElementRef并将事件处理程序设置为的onkeyup属性来捕获事件,但是elementRef.nativeElement没有运气

javascript angular

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