小编Nav*_*med的帖子

NativeScript安装问题

我只是想安装NavtiveScript,为此,我按照官方安装指南进行操作

http://docs.nativescript.org/angular/start/quick-setup but I am stuck at "Step 3: Install iOS and Android requirements"

当我在命令提示符中运行以下命令时(具有管理权限)

@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://www.nativescript.org/setup/win'))"
Run Code Online (Sandbox Code Playgroud)

一切似乎安装没有任何问题.但是当我尝试通过命令验证安装时,"tns doctor"我返回以下警告:

 D:\>tns doctor
WARNING: adb from the Android SDK is not installed or is not configured properly.
For Android-related operations, the NativeScript CLI will use a built-in version of adb.
To avoid possible issues with the native Android emulator, Genymotion or connected
Android devices, verify that you have installed the latest Android SDK and
its dependencies …
Run Code Online (Sandbox Code Playgroud)

nativescript angular2-nativescript

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

如何将Angular 2 RC 1(或更早版本)表格迁移到Angular 2 RC 2/RC 4新表格

我需要将现有的Angular 2 RC 1应用程序迁移到Angular 2 RC 4.作为其中的一部分,我还需要将现有的表单移动到Angular 2 RC 4 New Forms.

任何人都可以指导,如何将现有表格更新为新表格.

angular2-forms angular2-directives angular2-template angular

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

Angular 2媒体查询

我想知道Angular 2提供了一种确定客户端设备(大屏幕,中等或小屏幕)的方法,或者可能是屏幕宽度,基本上可以显示或隐藏某些内容(从dom中删除).

angular2-template angular2-services angular

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

使用箭头键进行Angular2导航

我正在开发一个Angular2项目,其中我有一个项目列表,然后单击任何项​​目使用项目详细信息组件显示其详细信息页面.我试图找到一种方法,允许用户使用向右和向左箭头键导航项目.

所以,我有一个项目列表,例如当用户单击列表中的第一项显示项目详细信息时,我现在想要的是当用户按右箭头键时它应该自动加载列表中下一项的详细信息.

我有两个组件ItemsListComponent和ItemDetailsComponent,每个组件都有自己的路由,ItemDetailsComponent有一个参数id.我有一个存储在ItemsService中的项目列表.

我在ItemDetails组件中有两个按钮,用于显示Next和Previous项,每个都绑定到showNext(id),showPrevious(id)函数在同一个组件上.

一切正常,但我无法将右/左箭头KeyPress事件链接到showNext(id)和showPrevious(id)函数.

我想到了一种方法,即在组件构造函数中使用addEventListener在文档中添加一个事件监听器,但这似乎不是一个优雅的解决方案.

任何与此相关的帮助都将受到高度赞赏.

PS:我没有使用jQuery,所以寻找一个纯粹的Angular2解决方案

angular

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

Angular 2 RC 6 AoT编译器无法正常工作

我刚刚将我的项目更新为Angular 2 RC 6.我现在正在尝试使用Ahead of Time(AoT)编译,如博客文章http://angularjs.blogspot.com/中所述,但没有成功.

我在ASP.Net中构建项目时没有使用angular cli.

正如博客文章所暗示的,我已经安装了@ angular/compiler-cli

但是当我尝试从命令提示符运行ngc时,它会出错

'ngc' is not recognized as an internal or external command,
operable program or batch file.


npm run ngc
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "ngc"
npm ERR! node v6.4.0
npm ERR! npm  v3.10.3

npm ERR! missing script: ngc
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following …
Run Code Online (Sandbox Code Playgroud)

angular2-services angular2-compiler angular

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

如何检查是否在组件上触发了更改检测

在我的应用程序中,我想设置手动更改检测.为此,我将ChangeDetectionStrategry设置为OnPush,每当组件发生更改时,我使用detectChanges手动运行更改检测.

如果我在父组件上将ChangeDetectionStrategy设置为OnPush,根据我的理解,它将仅在父组件上运行一次更改检测,在子组件上只运行一次,即使我没有在子组件上将ChangeDetectionStrategy设置为OnPush.如果父组件有任何更改,我在父组件中运行detectChanges().如果子组件有任何变化,我在子组件中运行detectChanges().

请建议这是正确的方法吗?还是有更好的方法吗?

其次,有没有办法检查它是否按预期工作,并且没有对特定组件执行更改检测.

angular2-directives angular2-template angular2-changedetection angular

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

Angular 2 在 http 调用的情况下订阅/取消订阅 Observables

我最近了解到,我们必须在 Angular 销毁组件之前取消订阅,否则可能会导致内存泄漏。

我还知道我们可以获得订阅的引用,并通过调用该订阅的取消订阅方法来订阅。例如

private sub: any;

ngOnInit() {
  this.sub = this.route.params.subscribe(params => {
     let id = +params['id']; // (+) converts string 'id' to a number
     this.service.getHero(id).then(hero => this.hero = hero);
   });
}


ngOnDestroy() {
  this.sub.unsubscribe();
}
Run Code Online (Sandbox Code Playgroud)

在 HTTP 调用的情况下也有必要吗?如果是,那么这种情况下的最佳实践是什么。

例如,我们通常有这样的东西通过 HTTP 发布一些数据

let body = JSON.stringify({ name });
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });

this.http.post(this.heroesUrl, body, options)
                .map(this.extractData)
                .subscribe((data) => {
                 //do something with data
                })
                .catch(this.handleError);
Run Code Online (Sandbox Code Playgroud)

下面的方法可行吗?这是在 HTTP …

angular2-services angular

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

Angular 2 Observable with ChangeDetectionStrategy.OnPush 和异步管道不起作用

我使用 observable 将列表从服务返回到我的组件,在我的组件中我使用 ChangeDetectionStrategy.OnPush 并且在模板中我使用异步管道,希望这会带来一些性能优势,因为更改检测不是一直执行但仅当有新内容可用时。

以下是我的服务:

import { Injectable, Inject, EventEmitter } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';

@Injectable()
export class ListService {

    public _list$: Subject<any[]>;

    private list: any[] = [];

    constructor() {
        this._list$ = <Subject<any>>new Subject();
    }

    get list$() {
        return this._list$.asObservable();
    }

    loadList() {
        //if this.list is populated through an http call the view is updated, 
        //if its a static list like below, it doesn't trigger view update.
        //this.list = …
Run Code Online (Sandbox Code Playgroud)

observable angular2-template angular2-services ngrx angular

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

FCM:如果用户订阅了多个主题,如何避免重复通知

假设用户 A 订阅了主题 T1、T2 和 T3。

如果我向主题 T1 和 T3 发送相同的通知。A会收到两个通知吗?

如果是这样,如何避免这种重复通知?

谢谢

subscribe firebase firebase-cloud-messaging firebase-notifications

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

Angular 2 RC 5 Bootstrap自定义HTTP类

在Angular 2 RC 4中,我有一个类HttpLoading,它扩展了Angular2的原始Http

我可以使用以下代码在bootstrap中使用它而没有任何问题:

bootstrap(AppComponent, [
    HTTP_PROVIDERS,
    provide(RequestOptions, { useClass: DefaultRequestOptions }),
    provide(Http, {
        useFactory: (backend: XHRBackend, defaultOptions: RequestOptions) => new HttpLoading(backend, defaultOptions),
        deps: [XHRBackend, RequestOptions]
    })
]).catch(err => console.error(err));
Run Code Online (Sandbox Code Playgroud)

我的DefaultRequest选项类

import { Injectable } from '@angular/core';
import { Headers, BaseRequestOptions } from '@angular/http';

@Injectable()
export class DefaultRequestOptions extends BaseRequestOptions {
    headers: Headers = new Headers({
        'Content-Type': 'application/json'
    });
}
Run Code Online (Sandbox Code Playgroud)

我的HttpLoading类看起来像这样:

import { Http, RequestOptionsArgs, ConnectionBackend, RequestOptions, Response } from '@angular/http'
import { Injectable } from '@angular/core'
import {GlobalService} …
Run Code Online (Sandbox Code Playgroud)

typescript angular2-directives angular2-services angular

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