angular2

Angular2 handling http response

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I just have a question regarding structuring and handling responses from http requests within a service. I am using Angular2.alpha46 Typescript ( Just started testing it out- which I love... Ps.. Thank you all the people who have been working on it and contributing via github ) So take the following: login-form.component.ts import {Component, CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/angular2'; import {UserService} from '../../shared/service/user.service'; import {Router} from 'angular2/router'; import {User} from '../../model/user

MVC 6 Routing, SPA fallback + 404 Error Page

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: With RC1 of ASP.NET Core 1.0's MVC 6 you can map routes from within your Startup.Configure function when invoking app.UseMvc . I have mapped a "spa-fallback" route that will ensure that the HomeController and Index view are the defaults like so: public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { // ... omitted for brevity app.UseExceptionHandler("/Home/Error"); app.UseStatusCodePagesWithRedirects("/Home/Error/{0}"); app.UseMvc(routes => { routes.MapRoute("default", "{controller=Home}/

TypeError: Cannot read property 'post' of undefined in [null]

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: In my Angular 2 project ListingService can't get data from server via post. I'm getting this error: EXCEPTION : TypeError : Cannot read property 'post' of undefined in [ null ] ORIGINAL EXCEPTION : TypeError : Cannot read property 'post' of undefined ORIGINAL STACKTRACE : TypeError : Cannot read property 'post' of undefined at ListingService . getListings ( http : //localhost:3000/app/listing.service.js:30:30) at ListingsComponent . getListings ( http : //localhost:3000/app/listings.component.js:45:41) at ListingsComponent .

Angular 2 - View not updating after model changes

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a simple component which calls a REST api every few seconds and receives back some JSON data. I can see from my log statements and the network traffic that the JSON data being returned is changing, and my model is being updated, however, the view isn't changing. My component looks like: import {Component, OnInit} from 'angular2/core'; import {RecentDetectionService} from '../services/recentdetection.service'; import {RecentDetection} from '../model/recentdetection'; import {Observable} from 'rxjs/Rx'; @Component({ selector: 'recent

Angular2: Unsubscribe from host listener [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Programmatically (un)register to event with Angular 2 2 answers If I subscribe to an event in an Angular2 component using host{}, how can I unsubscribe from the event? @Component({ selector: "foo", host: { "(window:resize)": "doSomething($event)" } }); I've tried to use $event to unsubscribe, but the event itself never presents the scenario in which I want to unsubscribe. For now, I'm just doing a poor man's short circuit, but I'd prefer to avoid the extra checks involved in short circuiting. Poor

How to install a component wrapper for Angular2 (Dragula in particular)

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm fairly new with both npm and Angular2. I've followed Angular2's tutorials on creating an initial app and I already have something fairly substantial. https://angular.io/docs/ts/latest/tutorial/ I need to add drag/drop ability to my app and believe I should probably use something native to Angular rather than jquery-ui. I've found this plugin: https://github.com/valor-software/ng2-dragula I've followed the instructions in the README, and it appears it's been installed. It's present under node_modules and ng2-dragula": "^1.0.3

Angular2/Http (POST) headers

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm unable to change the headers when doing a POST request. I tried a couple of things: Simple class: export class HttpService { constructor(http: Http) { this._http = http; } } I tried: testCall() { let body = JSON.stringify( { "username": "test", "password": "abc123" } ) let headers = new Headers(); headers.append('Content-Type', 'application/json'); // also tried other types to test if its working with other types, but no luck this._http.post('http://mybackend.local/api/auth', body, { headers: headers }) .subscribe( data => { console.log

Angular2 EventEmitter fire to parent component

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to fire an Event from the child component to the parent component. @Component ({ template : '<foo></foo>' }) export class ParentComponent { onDoSomething ( $event ){ //do work here } } @Component ({ selector : 'foo' template :< button ( click )= "onClick($event)" > MyButton </ button > }) export class ChildComponent { myEvent eventName = new EventEmitter (); onClick ( button ){ this . eventName . emit ( button ); } } How do i get this to work? 回答1: You define an EventEmitter in your child component with @Output

Importing lodash into app.ts file

匿名 (未验证) 提交于 2019-12-03 00:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying lodash uniqBy function to filter in my Angular 2 application. But, I am getting error in import statement import * as _ from 'lodash'; . I tried import _ from 'lodash'; , import _ from 'lodash/lodash'; , import * as _ from 'lodash/lodash'; also, but getting the same error i.e. Cannot find module 'lodash' . After checking angular2 failing lodash import , and Importing lodash into angular2 + typescript application , I mapped lodash to my system.config like so <script> System.config({ packages: { app: { format: 'register',

(1)ionic2的新特性

混江龙づ霸主 提交于 2019-12-02 21:51:14
ionic2的新特性 ionic2是基于Angular2构建的.相对与ng1,ng2几乎是完全的推倒重建的新框架. 虽然Angular原有的部分仍然在新版本中得以保留,但是开发者必须注意那些新的语法和结构变化.你可以通过这个篇文章了解Angular2的变化 learn angular2 对于ionic,如果你是学习过ionic1,那么ionic2将不会让你感到陌生.V1(ionic1版本)中的概念仍然留存于V2中,但是他们看上去可能会有些不同.你仍然可以看到V1中熟悉的views和controllers,但是在V2中,他们被合并到了一个模块之中. 对于同一个例子,让我们看一下两个版本的实现方法 V1的实现: .config(function($stateProvider){ $stateProvider .state('main', { url: '/', templateUrl: 'templates/main.html', controller: 'MainCtrl' }) }) .controller('MainCtrl', function(){ }) V2的实现 @Page({ templateUrl:'main/main.html'})export class MainCmp { constructor(){ } } 其他的改变虽然也有很大不同