Tag: angular

Angular2代码中的TypeScript错误:无法find名称'模块'

我定义了以下的Angular2组件: import {Component} from 'angular2/core'; @Component({ selector: 'my-app', moduleId: module.id, templateUrl: './app.component.html' }) export class AppComponent { } 当我尝试编译这个,我得到第5行的以下错误: src/app/app.component.ts(5,13): error TS2304: Cannot find name 'module'. 我相信module.id是指CommonJS modulevariables(见这里 )。 我已经在tsconfig.json中指定了CommonJS模块系统: { "compilerOptions": { "target": "es5", "module": "commonjs", "declaration": false, "removeComments": true, "noLib": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "sourceMap": true, "pretty": true, "allowUnreachableCode": false, "allowUnusedLabels": false, […]

Android中的圆形button

我想在Android程序中创build四舍五入的button。 我看过如何创build圆angular的EditText? 我想要达到的是: 圆形的边缘button 更改不同状态下的button背景/外观(如Onclick,Focus) 使用我自己的PNG作为背景,而不是创build一个形状。

angular2 ngIf和CSS过渡/animation

我想要一个div在angular2中使用CSS从右侧滑入。 <div class="note" [ngClass]="{'transition':show}" *ngIf="show"> <p> Notes</p> </div> <button class="btn btn-default" (click)="toggle(show)">Toggle</button> 我工作正常,如果我只使用[ngClass]切换类和利用不透明度。 但李先生不希望从一开始就渲染这个元素,所以我先用ng来“隐藏”它,但是这个转换不会起作用。 .transition{ -webkit-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out; -moz-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out; -ms-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out ; -o-transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out; transition: opacity 1000ms ease-in-out,margin-left 500ms ease-in-out; margin-left: 1500px; width: 200px; opacity: 0; } .transition{ opacity: […]

如何计算整数范围内的每个数字?

想象一下,你出售那些用于房屋,储物柜门,酒店房间等的金属数字。当你的客户需要门牌号码时,你需要找出每个数字有多less个数字: 1到100 51至300 1到2,000,左边是零 显而易见的解决scheme是从第一个到最后一个数字执行一个循环,将计数器转换为左侧或没有零的string,提取每个数字,并将其用作索引来递增10个整数的数组。 我想知道是否有更好的方法来解决这个问题,而不必遍历整个整数范围。 任何语言或伪代码的解决scheme都是受欢迎的。 编辑: 答案审查 CashCommons和Wayne Conrad的 John评论说,我目前的做法很好,也足够快。 让我用一个愚蠢的比喻:如果你在1分钟内完成棋盘上方块的计算任务,你可以通过逐个计算方块来完成任务,但更好的解决scheme是计算边和做一个乘法,因为你以后可能会被要求去计算build筑物中的瓷砖。 亚历克斯·雷斯纳(Alex Reisner)指出了一个非常有趣的math定律,不幸的是,这个问题似乎并不相关。 Andresbuild议我使用相同的algorithm,但用%10操作而不是子string提取数字。 约翰在CashCommons和phordbuild议预先计算所需的数字并将它们存储在查找表中,或者对于原始速度来说,它是一个数组。 如果我们有一个绝对的,不可移动的,最大的整数值,这可能是一个很好的解决scheme。 我从来没有见过其中之一。 高性能标记和filter计算了各种范围所需的数字。 一毫秒的结果似乎表明有一个比例,但其他数字的结果显示不同的比例。 filter发现了一些公式,可以用来计数十位数的数字。 Robert Harvey在MathOverflow上发表了一个非常有趣的经历。 math家之一用math符号写了一个解决scheme。 Aaronaught使用math开发和testing了一个解决scheme。 发布后,他回顾了从math溢出发起的公式,并发现它的缺陷(指向Stackoverflow :)。 noahlavine开发了一个algorithm,并以伪代码的forms呈现。 一个新的解决scheme 读完所有的答案,并做了一些实验,我发现,从1到10 n -1的整数范围: 对于数字1至9,需要n * 10 (n-1)个片段 对于数字0,如果不使用前导零,则需要n * 10 n-1 – ((10 n -1)/ 9) 对于数字0,如果使用前导零,则需要n * 10 n-1 -n 第一个公式是filter (也许是其他人)发现的,我发现了另外两个是通过反复试验(但是可能包含在其他答案中)。 例如,如果n = […]

Angular2:子组件访问父类variables/函数

我有一个父组件中的variables,可能会由孩子改变,父母将在视图中使用此variables,因此必须传播更改。 import {Component, View} from 'angular2/core'; @Component({selector: 'parent'}) @View({ directives: [Child], template: `<childcomp></childcomp>` }) class Parent { public sharedList = new Array(); constructor() { } } @Component({selector: 'child'}) @View({template: `…`}) class Child { constructor() { //access 'sharedList' from parent and set values sharedList.push("1"); sharedList.push("2"); sharedList.push("3"); sharedList.push("4"); } }

angular2 rc.5自定义input,没有值的访问器用于未指定名称的表单控件

我有这样简单的自定义input组件, import {Component, Provider, forwardRef} from "@angular/core"; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from "@angular/forms"; const noop = () => {}; const CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR: any = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CustomInputComponent), multi: true }; @Component({ selector: 'custom-input', template: ` <input class="form-control" [(ngModel)]="value" name="somename" (blur)="onTouched()"> `, providers: [CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR] }) export class CustomInputComponent implements ControlValueAccessor{ //The internal data model […]

当一些调用工作而另一些调用失败时,$ q.all()会发生什么?

当一些调用工作而另一些调用失败时,$ q.all()会发生什么? 我有以下代码: var entityIdColumn = $scope.entityType.toLowerCase() + 'Id'; var requests = $scope.grid.data .filter(function (rowData, i) { return !angular.equals(rowData, $scope.grid.backup[i]); }) .map(function (rowData, i) { var entityId = rowData[entityIdColumn]; return $http.put('/api/' + $scope.entityType + '/' + entityId, rowData); }); $q.all(requests).then(function (allResponses) { //if all the requests succeeded, this will be called, and $q.all will get […]

覆盖地球与六angular形地图瓷砖

许多战略游戏使用六angular形瓷砖。 其中一个主要的优点是任何瓦片的中心与其所有相邻的瓦片之间的距离是相同的。 我想知道是否有人想把传统的地理系统(经度/纬度)与六边形瓷砖系统结合起来。 我认为用六angular形瓷砖覆盖地球仪并能够将地理坐标映射到瓷砖会很有趣。 有没有人看过任何远在此之前? UPDATE 我正在寻找一种细分球体表面的方法,以便每个球体具有相同的表面积。 理想的情况是,相邻分区的中心是等距的。

何时使用'npm start'以及何时使用'ng serve'?

ng serve通过一个开发服务器来服务一个Angular项目 npm start运行包的“scripts”对象的“start”属性中指定的任意命令。 如果在“scripts”对象上没有指定“start”属性,它将运行节点server.js。 看来ng serve启动embedded式服务器,而npm start启动节点服务器。 有人可以抛出一些光?

添加到NgModule.schemas的CUSTOM_ELEMENTS_SCHEMA仍显示错误

我刚刚从Angular 2 rc4升级到rc6,并且遇到麻烦。 我在控制台上看到以下错误: Unhandled Promise rejection: Template parse errors: 'cl-header' is not a known element: 1. If 'cl-header' is an Angular component, then verify that it is part of this module. 2. If 'cl-header' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. ("<main> [ERROR ->]<cl-header>Loading […]