Tag: angular

在Angular中迭代对象

我正在尝试在Angular 2 Alpha 28中做一些事情,并在字典和NgFor中遇到问题。 我在TypeScript中有一个接口,看起来像这样: interface Dictionary { [ index: string ]: string } 在JavaScript中,这将转化为一个对象,其中的数据可能看起来像这样: myDict={'key1':'value1','key2':'value2'} 我想迭代这个,并试着这个: <div *ngFor="(#key, #value) of myDict">{{key}}:{{value}}</div> 但无济于事,下面也没有一个工作: <div *ngFor="#value of myDict">{{value}}</div> <div *ngFor="#value of myDict #key=index">{{key}}:{{value}}</div> 在所有情况下,我得到像“意外的标记”或“无法find”iterableDiff“pipe道支持对象” 我在这里错过了什么? 这不可能了吗? (第一种语法在Angular 1.x中有效)或者迭代对象的语法是不同的?

ng-repeat中的自定义sortingfunction

我有一组显示一定数量的图块,具体取决于用户select哪个选项。 现在我想通过显示的任何数字来实现一个sorting。 下面的代码显示了我如何实现它(通过获取/设置父卡范围中的值)。 现在,因为orderBy函数需要一个string,我试图在名为curOptionValue的卡片范围中设置一个variables,然后对其进行sorting,但似乎不起作用。 所以问题就变成了,我如何创build一个自定义的sorting函数? <div ng-controller="aggViewport" > <div class="btn-group" > <button ng-click="setOption(opt.name)" ng-repeat="opt in optList" class="btn active">{{opt.name}}</button> </div> <div id="container" iso-grid width="500px" height="500px"> <div ng-repeat="card in cards" class="item {{card.class}}" ng-controller="aggCardController"> <table width="100%"> <tr> <td align="center"> <h4>{{card.name}}</h4> </td> </tr> <tr> <td align="center"><h2>{{getOption()}}</h2></td> </tr> </table> </div> </div> 和控制器: module.controller('aggViewport',['$scope','$location',function($scope,$location) { $scope.cards = [ {name: card1, values: […]

Angular 2找不到Promise,Map,Set和Iterator

在安装angular 2之后,我的脚本编译器不断收到有关找不到Promise,Map,Set和Iterator的错误。 直到现在我忽略了他们,但现在我需要承诺,所以我的代码将工作。 import {Component} from 'angular2/core'; @Component({ selector: 'greeting-cmp', template: `<div>{{ asyncGreeting | async}}</div>` }) export class GreetingCmp { asyncGreeting: Promise<string> = new Promise(resolve => { // after 1 second, the promise will resolve window.setTimeout(() => resolve('hello'), 1000); }); } Additional information: npm -v is 2.14.12 node -v is v4.3.1 typescript v is 1.6 […]

公式px到dp,dp到px android

我正试图计算可变数量的像素密度独立像素,反之亦然。 这个公式(px to dp): dp = (int)(px / (displayMetrics.densityDpi / 160)); 在小型设备上不起作用,因为它被零除。 这是我的DP到PX公式: px = (int)(dp * (displayMetrics.densityDpi / 160)); 有人能给我一些指点吗?

如何在Angular 2中创build一个简单的JSONPasynchronous请求?

我试图将下面的Angular 1代码转换成Angular 2: $http.jsonp('https://accounts.google.com/logout'); 它需要是一个JSONP请求来跳过CORS策略问题。

如何在angular度js应用程序的量angular器中禁用animation

任何人都可以build议我如何在angular度js应用程序中执行量angular器testing时禁用animation。 我已经在我的量angular器configuration文件中添加了下面的代码,但是这并没有帮助我: var disableNgAnimate = function() { angular.module('disableNgAnimate', []).run(function($animate) { $animate.enabled(false); }); }; browser.addMockModule('disableNgAnimate', disableNgAnimate);

如何在angularjs e2e量angular器testing中上传文件

我想用angularjs e2etesting来testingfile upload。 你如何在e2etesting中做到这一点? 我通过咕噜的业力运行我的testing脚本。

Angular2和Observable:不能绑定到'ngModel',因为它不是'select'的已知属性

编辑:更新Plunkr: http ://plnkr.co/edit/fQ7P9KPjMxb5NAhccYIq?p=preview 这部分工作: <div *ngFor="let entry of entries | async"> Label: {{ entry.label }}<br> Value: {{ entry.value }} </div> 但是我在select框有问题,错误信息是: 无法绑定到'ngModel',因为它不是'select'的已知属性 整个组件: //our root app component import {Component} from '@angular/core'; import {NgFor} from '@angular/common'; import {HTTP_PROVIDERS, Http} from '@angular/http'; import 'rxjs/Rx'; import {Observable} from 'rxjs/Rx'; @Component({ selector: 'my-app', providers: [HTTP_PROVIDERS], template: ` <select [(ngModel)]="selectValue" […]

Angular 2:第一个服务成功时的两个后端服务调用

在我的Angular 2应用程序中,我有如下的后端服务。 getUserInterests() { return this.http.get('http://localhost:8080/test/selections').map((res: Response) => res.json()); } 在调用这个服务之后,我想在前一个成功的情况下调用另一个服务。 第二服务 let params: URLSearchParams = new URLSearchParams(); params.set('access_token', localStorage.getItem('access_token')); return this.http.get('http://localhost:8080/user/selections', { search: params }).map((res: Response) => res.json()); 这两个服务分别返回两个JSON数组。 然后我需要用这两个数组做一些login。 EDITED service.ts getUserInterests() { return this.http.get('http://localhost:8080/test/selections').map((res: Response) => res.json()); } getSavedSelections() { let params: URLSearchParams = new URLSearchParams(); params.set('access_token', localStorage.getItem('access_token')); return this.http.get('http://localhost:8080/interest/user/selections', { search: […]

Angular和SVGfilter

在AngularJS中使用SVG时,我遇到了一个奇怪的行为。 我正在使用$routeProvider服务来configuration我的路线。 当我把这个简单的SVG放在我的模板里时,一切都很好: <div id="my-template"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect fill="red" height="200" width="300" /> </svg> // … </div> 但是当我添加一个filter,例如这个代码: <div id="my-template"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <defs> <filter id="blurred"> <feGaussianBlur stdDeviation="5"/> </filter> </defs> <rect style="filter:url(#blurred)" fill="red" height="200" width="300" /> </svg> </div> 然后: 它在我的主页上工作 。 使用Firefox时 ,SVG 在其他页面上不再可见,但它仍然留下原来的空间。 使用Chrome ,SVG是可见的,但根本不模糊。 当我手动删除(使用Firebug) filter样式时,SVG再次可见。 这里是路由configuration: $routeProvider .when('/site/other-page/', { templateUrl : 'view/Site/OtherPage.html', […]