标签: angular

如何检测Angular中的路由变化?

我期待检测我的路线变化AppComponent.

此后,我将检查全局用户令牌以查看他是否已登录.然后,如果用户未登录,我可以重定向用户.

angular

352
推荐指数
16
解决办法
31万
查看次数

使用*ngFor访问键和对象的值

我有点困惑如何获取keyvalue同时使用angular2对象的*ngFor用于遍历的对象.我知道在角度1.x中有一个类似的语法

ng-repeat="(key, value) in demo"
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在angular2中做同样的事情.我尝试过类似的东西,没有成功:

<ul>
  <li *ngFor='#key of demo'>{{key}}</li>
</ul>

demo = {
    'key1': [{'key11':'value11'}, {'key12':'value12'}],
    'key2': [{'key21':'value21'}, {'key22':'value22'}],
  }
Run Code Online (Sandbox Code Playgroud)

以下是我的尝试:http ://plnkr.co/edit/mIj619FncOpfdwrR0KeG?p=preview

我怎样才能获得key1key2动态使用*ngFor?经过广泛搜索后,我发现了使用管道的想法,但我不知道如何去做.是否有任何内置管道在angular2中做同样的事情?

object typescript angular

349
推荐指数
14
解决办法
34万
查看次数

NgModule中的声明,提供程序和导入有什么区别?

我试图理解Angular(有时称为Angular2 +),然后我遇到了@Module:

  1. 进口

  2. 声明

  3. 供应商

遵循Angular快速入门

angular-module angular

349
推荐指数
6
解决办法
11万
查看次数

如何捆绑Angular应用程序进行生产

我想在这个帖子中跟踪和更新最新的(并且希望是最简单的)方法来捆绑Angular(版本2,4,...)以便在实时Web服务器上进行生产.

请在答案中包含Angular版本,以便我们可以更好地跟踪它何时转移到更高版本.

systemjs webpack angular-cli angular

337
推荐指数
6
解决办法
18万
查看次数

如何在Angular 2中的"select"中获得新选择?

我正在使用Angular 2(TypeScript).

我想为新的选择做点什么,但是我在onChange()中得到的东西总是最后选择.我怎样才能获得新的选择?

<select [(ngModel)]="selectedDevice" (change)="onChange($event)">
    <option *ngFor="#i of devices">{{i}}</option>
</select>

onChange($event) {
    console.log(this.selectedDevice);
    // I want to do something here for new selectedDevice, but what I
    // got here is always last selection, not the one I just select.
}
Run Code Online (Sandbox Code Playgroud)

typescript angular

331
推荐指数
8
解决办法
46万
查看次数

Angular HTTP GET与TypeScript错误http.get(...).map不是[null]中的函数

我在Angular中遇到HTTP问题.

我只想要GET一个JSON列表并在视图中显示它.

服务类

import {Injectable} from "angular2/core";
import {Hall} from "./hall";
import {Http} from "angular2/http";
@Injectable()
export class HallService {
    public http:Http;
    public static PATH:string = 'app/backend/'    

    constructor(http:Http) {
        this.http=http;
    }

    getHalls() {
           return this.http.get(HallService.PATH + 'hall.json').map((res:Response) => res.json());
    }
}
Run Code Online (Sandbox Code Playgroud)

HallListComponentgetHalls从服务中调用方法:

export class HallListComponent implements OnInit {
    public halls:Hall[];
    public _selectedId:number;

    constructor(private _router:Router,
                private _routeParams:RouteParams,
                private _service:HallService) {
        this._selectedId = +_routeParams.get('id');
    }

    ngOnInit() {
        this._service.getHalls().subscribe((halls:Hall[])=>{ 
            this.halls=halls;
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我有一个例外:

TypeError:this.http.get(...).map不是[null]中的函数 …

rxjs angular

326
推荐指数
6
解决办法
23万
查看次数

Angular EXCEPTION:没有Http的提供者

我正在使用EXCEPTION: No provider for Http!我的Angular应用程序.我究竟做错了什么?

import {Http, Headers} from 'angular2/http';
import {Injectable} from 'angular2/core'


@Component({
    selector: 'greetings-ac-app2',
    providers: [],
    templateUrl: 'app/greetings-ac2.html',
    directives: [NgFor, NgModel, NgIf, FORM_DIRECTIVES],
    pipes: []
})
export class GreetingsAcApp2 {
    private str:any;

    constructor(http: Http) {

        this.str = {str:'test'};

        http.post('http://localhost:18937/account/registeruiduser/',
            JSON.stringify(this.str),
            {
                headers: new Headers({
                    'Content-Type': 'application/json'
                })
            });
Run Code Online (Sandbox Code Playgroud)

angular

322
推荐指数
7
解决办法
21万
查看次数

如何在Angular中使用jQuery?

谁能告诉我,如何使用jQuery的

class MyComponent {
    constructor() {
        // how to query the DOM element from here?
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道有一些变通方法可以预先操作DOM元素的id,但是我希望有一种更简洁的方法.

jquery angular

321
推荐指数
16
解决办法
36万
查看次数

角度异常:无法绑定到'ngForIn',因为它不是已知的本机属性

我究竟做错了什么?

import {bootstrap, Component} from 'angular2/angular2'

@Component({
  selector: 'conf-talks',
  template: `<div *ngFor="let talk in talks">
     {{talk.title}} by {{talk.speaker}}
     <p>{{talk.description}}
   </div>`
})
class ConfTalks {
  talks = [ {title: 't1', speaker: 'Brian', description: 'talk 1'},
            {title: 't2', speaker: 'Julie', description: 'talk 2'}];
}
@Component({
  selector: 'my-app',
  directives: [ConfTalks],
  template: '<conf-talks></conf-talks>'
})
class App {}
bootstrap(App, [])
Run Code Online (Sandbox Code Playgroud)

错误是

EXCEPTION: Template parse errors:
Can't bind to 'ngForIn' since it isn't a known native property
("<div [ERROR ->]*ngFor="let talk in talks">
Run Code Online (Sandbox Code Playgroud)

angular2-directives angular

319
推荐指数
7
解决办法
10万
查看次数

找不到模块"@ angular-devkit/build-angular"

更新到Angular 6.0.1后,我收到以下错误ng serve:

Could not find module "@angular-devkit/build-angular" from "/home/Projects/myProjectName".
Error: Could not find module "@angular-devkit/build-angular" from "/home/Projects/myProjectName".
    at Object.resolve (/home/Projects/myProjectName/node_modules/@angular-devkit/core/node/resolve.js:141:11)
    at Observable.rxjs_1.Observable [as _subscribe] (/home/Projects/myProjectName/node_modules/@angular-devkit/architect/src/architect.js:132:40)
Run Code Online (Sandbox Code Playgroud)

ng update说一切都井然有序.删除node_modules文件夹和全新npm install安装也没有帮助.

我的项目基于[ng2-admin(Angular4版本)].(https://github.com/akveo/ngx-admin)这是我的package.json dependecies:

 "dependencies": {
    "@angular/animations": "^6.0.1",
    "@angular/common": "^6.0.1",
    "@angular/compiler": "^6.0.1",
    "@angular/core": "^6.0.1",
    "@angular/forms": "^6.0.1",
    "@angular/http": "^6.0.1",
    "@angular/platform-browser": "^6.0.1",
    "@angular/platform-browser-dynamic": "^6.0.1",
    "@angular/platform-server": "^6.0.1",
    "@angular/router": "^6.0.1",
    "@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.26",
    "@ngx-translate/core": "^10.0.1",
    "@ngx-translate/http-loader": "^3.0.1",
    "amcharts3": "github:amcharts/amcharts3",
    "ammap3": "github:amcharts/ammap3",
    "angular-table": "^1.0.4",
    "angular2-csv": "^0.2.5",
    "angular2-datatable": "0.6.0",
    "animate.css": "3.5.2",
    "bootstrap": "4.0.0-alpha.6", …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular angular6 angular-cli-v6

316
推荐指数
16
解决办法
46万
查看次数