Tag: angular

HTTP和HTTPClient在angular度4之间的区别?

我想知道哪个用来构build一个模拟Web服务来testingAngular程序?

Angular2 QuickStart npm start无法正常工作

我知道Angular2testing版刚刚发布,但我不能从他们的官方网站教程( https://angular.io/guide/quickstart )重现步骤。 也许有人有类似的问题,并知道该怎么做才能解决这个问题? 当我尝试用npm start命令启动应用程序时,我得到这样的输出结果: 0 info it worked if it ends with ok 1 verbose cli [ 'node', '/usr/local/bin/npm', 'start' ] 2 info using npm@2.7.4 3 info using node@v0.12.2 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 5 info prestart angular2-quickstart@1.0.0 6 info start angular2-quickstart@1.0.0 7 verbose unsafe-perm in lifecycle true 8 info […]

Angular 2 DI错误 – EXCEPTION:无法parsing所有参数

我已经在Angular 2中构build了一个基本的应用程序,并遇到了一个奇怪的问题,我无法将服务注入到其中一个组件中。 它会把它们注入到我创build的其他三个组件中。 对于初学者来说,这是服务(这是非常基本的,因为我只是现在正在testing的东西): import { Injectable } from '@angular/core'; @Injectable() export class MobileService { screenWidth: number; screenHeight: number; constructor() { this.screenWidth = window.outerWidth; this.screenHeight = window.outerHeight; window.addEventListener("resize", this.onWindowResize.bind(this) ) } onWindowResize(ev: Event) { var win = (ev.currentTarget as Window); this.screenWidth = win.outerWidth; this.screenHeight = win.outerHeight; } } 而它拒绝使用的组件: import { Component, } from '@angular/core'; […]

如何在Angular 2的“select”中获得新的select?

我正在使用Angular 2(TypeScript)。 我想为新的select做些什么,但是我得到的onChange()总是最后的select。 我怎样才能获得新的select? <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. }

Angular 2 http没有得到

我新来Angular 2仍然学习我正在尝试打一个电话的url,但即使在浏览器的networking中似乎没有通过我无法find被调用的URL。 该程序是去那个方法控制台日志logging上面和下面,得到调用,但没有任何获取调用 我的服务方法 import { Headers, Http, Response } from '@angular/http'; import { Injectable } from '@angular/core'; import { Persons } from './mock-people'; import { Person } from './person'; import {Observable} from 'rxjs/Rx'; getAllPersons():void{ console.log("Here"); this.http.get(`http://swapi.co/api/people/1`).map((response:Response) => { console.log(response.json()); response.json(); }); console.log("Comes here 2"); } 在app.module.ts中导入Httpmodule 我的控制台屏幕截图 安慰

Angular 2中的dynamic模板url

过去几天我一直在玩Angular 2,想知道是否可以为@View装饰器提供一个dynamic的templateUrl 。 我曾尝试传递一个函数,并返回一个stringforms,但整个函数只是变成一个string。 我之前还没有真正使用过Angular 1.x,所以我不知道我是否只是以错误的方式来解决这个问题,但这是否可能,还是有更好的方法来创builddynamic视图? 例如,如果用户没有login,我可能想显示一个表单,但如果他们login,则显示一条文本消息。 像这样的东西不起作用: @Component({ selector: 'my-component' }) @View({ // This doesn't work templateUrl: function() { return this.isLoggedIn ? 'logged-in.html' : 'logged-out.html'; } }) class MyComponent { constructor() { this.loggedIn = false; } } 任何帮助,将不胜感激。

如何select下拉protractorjs e2etesting的选项

我正在尝试使用量angular器从angular度e2etesting的下拉列表中select一个选项。 以下是select选项的代码片段: <select id="locregion" class="create_select ng-pristine ng-invalid ng-invalid-required" required="" ng-disabled="organization.id !== undefined" ng-options="o.id as o.name for o in organizations" ng-model="organization.parent_id"> <option value="?" selected="selected"></option> <option value="0">Ranjans Mobile Testing</option> <option value="1">BeaverBox Testing</option> <option value="2">BadgerBox</option> <option value="3">CritterCase</option> <option value="4">BoxLox</option> <option value="5">BooBoBum</option> </select> 我努力了: ptor.findElement(protractor.By.css('select option:1')).click(); 这给了我以下错误: 一个无效的或非法的string指定构build信息:版本:'2.35.0',修订:'c916b9d',时间:'2013-08-12 15:42:01'系统信息:os.name:'Mac OS X' ,os.arch:'x86_64',os.version:'10 .9',java.version:'1.6.0_65'驱动程序信息:driver.version:unknown 我也试过了: ptor.findElement(protractor.By.xpath('/html/body/div[2]/div/div[4]/div/div/div/div[3]/ng-include/div/div[2]/div/div/organization-form/form/div[2]/select/option[3]')).click(); 这给了我以下错误: ElementNotVisibleError:元素当前不可见,所以不能与命令持续时间或超时进行交互:9毫秒构build信息:版本:'2.35.0',修订版:'c916b9d',时间:'2013-08-12 15:42: 01'系统信息:os.name:'Mac […]

在app config,angular.js中使用自定义提供程序中的$ http

主要的问题 – 可能吗? 我试过没有运气.. 主app.js … var app = angular.module('myApp', ['services']); app.config(['customProvider', function (customProvider) { }]); … 提供者本身 var services = angular.module('services', []); services.provider('custom', function ($http) { }); 而我有这样的错误: Uncaught Error: Unknown provider: $http from services 有任何想法吗? 谢谢!

如何在C ++中使用PI常量

我想在一些C ++程序中使用PI常量和三angular函数。 我用include <math.h>得到三angular函数。 但是,在这个头文件中似乎没有PI的定义。 如何获得PI而无需手动定义?

使用Angular 2新路由器更改页面标题

使用新的路由器时,在浏览器中更改应用页面标题的正确方法是什么? *使用Angular 2 CLI