小编Fra*_*rzi的帖子

"ng-bootstrap"和"ngx-bootstrap"有什么区别?

"ng-bootstrap"和"ngx-bootstrap"有什么区别?它们是否相互关联?或者它们只是并发实现?

有人和他们一起工作,可以给出/解释两者的利弊吗?

使用"ng-bootstrap"我的意思是https://ng-bootstrap.github.io/#/home

与"ngx-bootstrap"我的意思是http://valor-software.com/ngx-bootstrap/.

两者都与Angular 4(不是AngularJS!)和Bootstrap 4有关.

请注意,这不是ngx-bootstrap和ng2 bootstrap之间重复的问题.

ng-bootstrap ngx-bootstrap angular

198
推荐指数
8
解决办法
6万
查看次数

如何将Angular CLI升级到最新版本

使用ng --version我得到:

@ angular/cli:1.0.0

这不是最新版本.

由于我的系统上全局安装了Angular CLI,为了升级它,我尝试了:

npm update angular-cli -g

但它不起作用,因为它保持1.0.0版本.

angular-cli angular

102
推荐指数
10
解决办法
45万
查看次数

如何在Angular2上使用onBlur事件?

你如何在Angular2中检测到onBlur事件?我想用它

<input type="text">
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我理解如何使用它吗?

javascript onblur angular

95
推荐指数
3
解决办法
17万
查看次数

将Angular2 TypeScript文件和JavaScript文件分隔到不同的文件夹中,可能是'dist'

我正在使用angular.io网站上的5分钟快速入门,其中包含如下文件结构:

angular2-quickstart
 app
   app.component.ts
   boot.ts
 index.html
 license.md
 package.json
 tsconfig.json
Run Code Online (Sandbox Code Playgroud)

tsconfig.json是这样的代码块:

{
  "compilerOptions": {
    "target": "ES5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules"
  ]
} 
Run Code Online (Sandbox Code Playgroud)

还有package.json:

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.0",
    "systemjs": "0.19.6",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "zone.js": "0.5.10" …
Run Code Online (Sandbox Code Playgroud)

javascript json angular

82
推荐指数
7
解决办法
4万
查看次数

使用angular2更新服务中组件的变量更改

我的应用程序有一个NameService,其中包含名称.

App,Navbar和TheContent有两个子组件引用此服务.只要服务中的名称发生变化,我希望它在两个其他组件中更新.我怎样才能做到这一点?

import {Component, Injectable} from 'angular2/core'

// Name Service

@Injectable()
class NameService {
  name: any;
  constructor() {
    this.name = "Jack";
  }
  change(){
    this.name = "Jane";
  }
}

// The navbar
@Component({
  selector: 'navbar',
  template: '<div>This is the navbar, user name is {{name}}.</div>'
})
export class Navbar {
  name: any;
  constructor(nameService: NameService) {
    this.name = nameService.name;
  }
}

// The content area
@Component({
  selector: 'thecontent',
  template: '<div>This is the content area. Hello user {{name}}. <button (click)=changeMyName()>Change the name</button></div>'
})
export …
Run Code Online (Sandbox Code Playgroud)

javascript angular

72
推荐指数
3
解决办法
7万
查看次数

组件Angular 2中的重定向

我有一个简单的方法,在它的最后我想重定向到另一个组件:

export class AddDisplay{
  display: any;

  addPairTo(name: string, pairTo: string){
    this.display = {};
    this.display.name = name;
    this.display.pairTo = pairTo;

  }
}
Run Code Online (Sandbox Code Playgroud)

我想做的是在方法结束时重定向到另一个组件:

export class AddDisplay{
  display: any;

  addPairTo(name: string, pairTo: string){
    this.display = {};
    this.display.name = name;
    this.display.pairTo = pairTo;

    this.redirectTo('foo');
  }
}
Run Code Online (Sandbox Code Playgroud)

我如何在Angular 2中实现这一目标?

javascript angular

69
推荐指数
3
解决办法
9万
查看次数

Angular 2快速入门:意外令牌<

我试图根据http://angular.io上的快速入门设置角度2 .我完全按照指南中的描述复制了每个文件,但是当我运行npm start并打开浏览器选项卡时,我在控制台中收到以下错误的"正在加载...":

Uncaught SyntaxError: Unexpected token <                        (program):1
     __exec @ system.src.js:1374
Uncaught SyntaxError: Unexpected token <          angular2-polyfills.js:138
    Evaluating http://localhost:3000/app/boot
    Error loading http://localhost:3000/app/boot
Run Code Online (Sandbox Code Playgroud)

这是我的app.component.ts:

import {Component} from 'angular2/core';

@Component({
    selector: 'my-app',
    template: `<h1>My First Angular 2 App</h1>`
})
export class AppComponent {

}
Run Code Online (Sandbox Code Playgroud)

我的boot.ts:

import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';

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

我的index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Angular 2 Quick Start</title>

    <script src="node_modules/es6-shim/es6-shim.js"></script>
    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script …
Run Code Online (Sandbox Code Playgroud)

javascript angular

59
推荐指数
3
解决办法
7万
查看次数

Angular 2路由器事件监听器

如何在Angular 2路由器中监听状态变化?

在Angular 1.x中我使用了这个事件:

$rootScope.$on('$stateChangeStart',
    function(event,toState,toParams,fromState,fromParams, options){ ... })
Run Code Online (Sandbox Code Playgroud)

所以,如果我在Angular 2中使用这个eventlistener:

window.addEventListener("hashchange", () => {return console.log('ok')}, false);
Run Code Online (Sandbox Code Playgroud)

它不是返回'ok',然后从JS更改状态,然后才运行浏览器history.back()函数.

使用router.subscribe()函数作为服务:

import {Injectable} from 'angular2/core';
import {Router} from 'angular2/router';

@Injectable()
export class SubscribeService {
    constructor (private _router: Router) {
        this._router.subscribe(val => {
            console.info(val, '<-- subscribe func');
        })
    }
}
Run Code Online (Sandbox Code Playgroud)

在路由中初始化的组件中注入服务:

import {Component} from 'angular2/core';
import {Router} from 'angular2/router';

@Component({
    selector: 'main',
    templateUrl: '../templates/main.html',
    providers: [SubscribeService]
})
export class MainComponent {
    constructor (private subscribeService: SubscribeService) {}
}
Run Code Online (Sandbox Code Playgroud)

我将此服务注入其他组件,例如本例中.然后我改变状态,console.info()在服务中不起作用.

我做错了什么?

javascript typescript angular2-routing angular

59
推荐指数
3
解决办法
8万
查看次数

Angular2:MVC,MVVM还是MV*?

由于其双向数据绑定功能,Angular one或多或少遵循MVV*设计原则.

Angular2正在采用基于组件的UI,这是React开发人员可能熟悉的概念.从某种意义上说,Angular 1.x控制器和指令模糊了新的Angular 2 Component.

这意味着在Angular 2中没有控制器也没有指令.相反,组件有一个选择器,它对应于组件将表示的html标签,而@View则指定要填充的组件的HTML模板.

Angular2仍然实现双向数据绑定,但不包含模型,例如,如果我有一个@Component显示文章列表和一个class定义文章对象的模型:

class Article {
title: string;
link: string;
votes: number;

constructor(title: string, link: string, votes?: number){
    this.title = title;
    this.link = link;
    this.votes = votes || 0;
}
Run Code Online (Sandbox Code Playgroud)

这在MVC模式中将被视为模型.

那么考虑到这个Angular最接近的设计模式呢?

model-view-controller mvvm angular

56
推荐指数
6
解决办法
5万
查看次数

如何在Angular中使用带SASS的Bootstrap 4

我想在使用Angular CLI创建的Angular(4+)项目中使用Bootstrap 4和SASS.

特别是我需要:

  • 使用SASS而不是CSS作为全局样式和组件样式
  • 编译Bootstrap SASS源以及我的自定义*.scss样式
  • 确保我的自定义样式覆盖Bootstrap源,因此我可以在需要时覆盖Bootstrap源,而无需编辑Bootstrap源本身(可以轻松升级Bootstrap源版本)
  • 每当我的任何*.scss文件(包括组件和全局样式)更改为ng serve脚本时,添加监视和自动重新编译

sass bootstrap-4 angular-cli angular

56
推荐指数
3
解决办法
4万
查看次数