Tag: angular

Angular2:以编程方式创build子组件

题 如何在父组件内创build子组件,然后使用Angular2将它们显示在视图中? 如何确保注射剂正确地注入到儿童组件中? 例 import {Component, View, bootstrap} from 'angular2/angular2'; import {ChildComponent} from './ChildComponent'; @Component({ selector: 'parent' }) @View({ template: ` <div> <h1>the children:</h1> <!– ??? three child views shall be inserted here ??? –> </div>`, directives: [ChildComponent] }) class ParentComponent { children: ChildComponent[]; constructor() { // when creating the children, their constructors // shall […]

什么是前叉Web服务器模型?

我想知道当Web服务器将自己描述为预分叉Web服务器时,究竟意味着什么。 我有几个例子,如独angular兽的ruby和pythongunicorn 。 更具体地说,这些是问题: 这个模型解决了什么问题? 预分叉Web服务器最初启动时会发生什么? 它如何处理请求? 此外,一个更具体的问题独angular兽/ gunicorn: 比方说,我有一个web应用程序,我想与(g)独angular兽运行。 在初始化时,webapp会做一些初始化的东西(例如填写额外的数据库条目)。 如果我configuration(g)独angular兽与多个工人,将初始化的东西多次运行?

search一个元素的后代

用量angular器什么是最好的方法来select子元素? 假设我们有下面的布局… <div id='parent_1'> <div class='red'>Red</div> <div class='blue'>Blue</div> </div> <div id='parent_2'> <div class='red'>Red</div> <div class='blue'>Blue</div> </div> 有了jQuery,我们可以做这样的事情。 var p1 = $('#parent_1'); var p1_red = $('.red', p1); //or p1.find('.red'); var p1_blue = $('.blue', p1); //or p1.find('.blue'); 但是使用量angular器是否有意义先获取父元素? 由于这样做var p1 = element('#parent_1'); 实际上并没有检索/search对象,直到getText()或其他东西被调用。 所以这样做.. 情况1 expect(p1.element('.red')).toBe('red'); expect(p1.element('.blue')).toBe('blue'); 要么 情景2 expect(element('#parent_1').element('.red')).toBe('red'); expect(element('#parent_1').element('.blue')).toBe('blue'); 要么 情景3 expect(element('#parent_1 > .red')).toBe('red'); expect(element('#parent_1 […]

如何在Angular 2中用TypeScript过滤数组?

对于我来说,ng-2亲子数据inheritance一直是个难题。 什么似乎可能是一个很好的工作实际的解决scheme是过滤我的数据总数组到一个由只有一个父id引用的子数据组成的数组。 换句话说:数据inheritance成为一个父ID的数据过滤。 在一个具体的例子中,这可以看起来像:过滤书籍数组,只显示具有特定store_id的书籍。 import {Component, Input} from 'angular2/core'; export class Store { id: number; name: string; } export class Book { id: number; shop_id: number; title: string; } @Component({ selector: 'book', template:` <p>These books should have a label of the shop: {{shop.id}}:</p> <p *ngFor="#book of booksByShopID">{{book.title}}</p> ` ]) export class BookComponent { @Input() store: […]

正弦结果取决于所使用的C ++编译器

我使用以下两个C ++编译器: cl.exe :适用于x86的Microsoft(R)C / C ++优化编译器版本19.00.24210 g ++ :g ++(Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010 当使用内置的正弦函数时,我得到不同的结果。 这并不重要,但有时候结果对我的使用来说太重要了。 这是一个“硬编码”值的例子: printf("%f\n", sin(5451939907183506432.0)); 结果与cl.exe: 0.528463 用g ++的结果: 0.522491 我知道g ++的结果更准确,我可以使用额外的库来得到相同的结果,但这不是我的观点。 我真的很明白这里发生了什么事情: cl.exe为什么错了? 有趣的是,如果我在param上应用模(2 * pi),那么我得到的结果与g ++相同。 [编辑]只是因为我的例子看起来疯了你们中的一些人:这是一个伪随机数发生器的一部分。 知道正弦的结果是否准确并不重要,我们只是需要它来给出一些结果。

angular2testing,我怎么模仿子组件

如何在茉莉花testing中模拟子组件? 我有MyComponent ,它使用MyNavbarComponent和MyToolbarComponent import {Component} from 'angular2/core'; import {MyNavbarComponent} from './my-navbar.component'; import {MyToolbarComponent} from './my-toolbar.component'; @Component({ selector: 'my-app', template: ` <my-toolbar></my-toolbar> {{foo}} <my-navbar></my-navbar> `, directives: [MyNavbarComponent, MyToolbarComponent] }) export class MyComponent {} 当我testing这个组件时,我不想加载和testing这两个子组件; MyNavbarComponent,MyToolbarComponent,所以我想嘲笑它。 我知道如何使用provide(MyService, useClass(…))来模拟服务,但我不知道如何模拟指令; 组件; beforeEach(() => { setBaseTestProviders( TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS ); //TODO: want to mock unnecessary directives for this component test // […]

如何在Angular2上使用onBlur事件?

你如何检测Angular2中的onBlur事件? 我想用它 <input type="text"> 任何人都可以帮助我理解如何使用它?

angular2 testing:无法绑定到'ngModel',因为它不是'input'的已知属性

我正在尝试为控制inputtestingangular2双向绑定。 这是错误: Can't bind to 'ngModel' since it isn't a known property of 'input'. app.component.html <input id="name" type="text" [(ngModel)]="name" /> <div id="divName">{{name}}</div> app.component.ts @Component({ selector: 'app-root', templateUrl: './app.component.html' }) export class AppComponent implements OnInit { name: string; } app.component.spec.ts import { TestBed, async } from '@angular/core/testing'; import { AppComponent } from './app.component'; import { AppService […]

没有findangular2 – 404 traceur

我已经遵循了起始指南,并扩展了以前的angular度2版本。 我已经更新了我的修订,并相应地改变了一切 当我运行Web服务器时,我现在收到traceur的错误404 … 这是我的项目结构: 相关文件: index.html的: <html> <head> <title>Kinepolis HR-tool</title> <base href="./"> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content="Kinepolis HR tool"> <meta name="author" content="Jeffrey Devloo!"> <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css" /> <!– CSS for PrimeUI –> <!– 1. Load libraries –> <!– Polyfill(s) for older browsers –> <script src="node_modules/es6-shim/es6-shim.min.js"></script> <script […]

2D欧几里得vector旋转

我坐在坐标(0, 1)有一个欧几里得vector。 我想围绕原点旋转90度(顺时针):( (0, 0) 。 如果我对这应该如何工作有一个正确的理解,旋转后的结果(x,y)坐标应该是(1, 0) 。 如果我将它旋转45度(仍然是顺时针),那么我会期望得到的坐标是(0.707, 0.707) 。 theta = deg2rad(angle); cs = cos(theta); sn = sin(theta); x = x * cs – y * sn; y = x * sn + y * cs; 使用上面的代码, angle值为90.0度,结果坐标是: (-1, 1) 。 而我真是太糊涂了。 在下面的链接中看到的例子肯定表示上面显示的相同的公式? 我做错了什么? 还是我误解了一个vector是如何旋转的?