angular2-template

Angular2: Cannot read property 'name' of undefined

走远了吗. 提交于 2019-12-16 20:27:23
问题 I am beginning to learn Angular2. I've been following the Heroes Tutorial provided at angular.io. All was working fine until, being annoyed by the clutter of HTML using the template, I used template URL in its place, and moved the HTML to a file named hero.html. The error that is generated is, "Cannot read property 'name' of undefined". Strangely, the heroes variable which points to an array of objects can be accessed so that ngFor will produce the correct amount of "li" tags according to the

Angular2: Cannot read property 'name' of undefined

六月ゝ 毕业季﹏ 提交于 2019-12-16 20:26:33
问题 I am beginning to learn Angular2. I've been following the Heroes Tutorial provided at angular.io. All was working fine until, being annoyed by the clutter of HTML using the template, I used template URL in its place, and moved the HTML to a file named hero.html. The error that is generated is, "Cannot read property 'name' of undefined". Strangely, the heroes variable which points to an array of objects can be accessed so that ngFor will produce the correct amount of "li" tags according to the

onsubmit return all the rows input values angular 2

一笑奈何 提交于 2019-12-14 03:18:10
问题 I'm new to angular 2. I have a table, which on click of 'add consignment' option, it adds a new row with serial number and multiple input slots. Now on adding more consignments (which adds more rows of multiple input slots in table), and entering information to all these rows and submitting, only the values of last row is being returned. Can someone please tell me how to return the values of all the multiple input rows from the table as one single object? Thank you. Below is my code: Template

Angular 2's two-way binding not working on initial load of electron app

本秂侑毒 提交于 2019-12-14 01:31:13
问题 I have the following files: topnav.component.ts import { Component } from '@angular/core'; import { EnvironmentService } from '../services/ipc/environment.service'; const { ipcRenderer } = electron; @Component({ selector: 'app-topnav', templateUrl: './topnav.component.html', styleUrls: ['./topnav.component.scss'] }) export class TopnavComponent { version: string = null; constructor(private environmentService: EnvironmentService) { this.environmentService.getVersionInfo(); ipcRenderer.on(

Angular 2 - Toggle button based on JSON response

这一生的挚爱 提交于 2019-12-13 22:38:41
问题 How can we toggle a button to Yes/No based on JSON response in angular 2? 回答1: Use following code to toggle button import {Component, NgModule, VERSION} from '@angular/core' import {BrowserModule} from '@angular/platform-browser' @Component({ selector: 'my-app', template: ` <div> <button *ngIf='toggleButton' (click)='toggleButton = false'>Button One</button> <button *ngIf='!toggleButton' (click)='toggleButton = true'>Button Two</button> </div> `, }) export class App { name:string;

Angular 2 components tree

浪子不回头ぞ 提交于 2019-12-13 22:24:24
问题 I'm developing my first application with Angular 2 and I have installed Augury plugin for Google Chrome, in order to help me debug the code. Here's the components tree and graph: This is the HTML template of my custom component (DocumentsList): <div class="container-fluid" style="margin-top: 10px"> <div class="table-row header"> <div class="column index">#</div> <div class="wrapper attributes"> <div class="wrapper title-comment-module-reporter"> <div class="wrapper title-comment"> <div class=

Is it advisable to call a method in a template expression?

吃可爱长大的小学妹 提交于 2019-12-13 22:17:22
问题 In Angular 2 is it advisable to use a component method in an expression? For example, I have the following component export class AreaComponent { totalLength: number; totalBreadth: number; totalheight: number; mylocalVar: number; totalSqft: number; myMethod(): number { let totalArea = this.totalLength * this.totalBreadth * this.totalheight; let myVar = 0; switch (this.mylocalVar) { case 0: myVar = 8; break; case 1: myVar = 9; break; case 2: myVar = 10; break; } this.totalSqft = totalArea *

Angular2 dynamic stylesheet element

孤者浪人 提交于 2019-12-13 15:21:12
问题 I'm loading some content from the beehance API in JSON, which has some text and the style info to make it look as it was configured in the editor. the text contained in the JSON has html tags and I add it with [innerHTML] { text: '<div class="sub-title">Lorem ipsum</div> <div class="paragraph">dolor sit amet</div>', ... } and the styles are something like "paragraph": { "color": "#3B3B3B", "font_family": "arial,helvetica,sans-serif", "font_size": "12px", "line_height": "1.4em", "text_align":

ANGULAR 2 - Component Shared Data Service

断了今生、忘了曾经 提交于 2019-12-13 15:13:39
问题 this has really been wreaking my head. I have a nice little app with social login setup using Firebase and Angular 2. Everything should be realtime. Basically when a user logs in via Facebook I want their personal info to be passed to a service and stored as an Observable and display instantly in any component that subscribes to the service, I then want to be able to access this Observable from within Components that are not directly linked to each other and may even be totally out of the

Will Angular 2 child routes refresh the parent route

流过昼夜 提交于 2019-12-13 13:28:45
问题 I have an application in which I route between children of a parent route in some situations. One will look like example.com/a/1/ another example.com/a/2/ will switching from 1 to 2 trigger a reload/render of the page a ? Like playing a video in a and have a routes outlet as sibling to that video, will this change of page trigger the video to reload? If so, can this be prevented? 回答1: No, it won't. The parent component will only be refreshed if you navigate away from it and then navigate to