Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

476
Views
TypeScript - Angular: cadena multilínea

Soy un principiante de Angular 2 y he escrito este fragmento de código en mi dev/app.component.ts :

 import {Component} from 'angular2/core'; @Component({ selector: 'my-app', template: '<h3 (click)="onSelect()"> {{contact.firstName}} {{content.lastName}}</h3>' }) export class AppComponent { public contact = {firstName:"Max", lastName:"Brown", phone:"3456732", email:"max88@gmail.com"}; public showDetail = false; onSelect() { this.showDetail=true; } }

Funciona, cuando voy al navegador "se muestra Max Brown".

Ahora, quiero escribir la parte de la plantilla en diferentes líneas como esta:

 import {Component} from 'angular2/core'; @Component({ selector: 'my-app', template: '<h3 (click)="onSelect()"> {{contact.firstName}} {{contact.lastName}}<h3>' }) export class AppComponent { public contact = {firstName:"Max", lastName:"Brown", phone:"3456732", email:"max88@gmail.com"}; public showDetail = false; onSelect() { this.showDetail=true; } }

Pero me sale este error en la consola de Chrome:

 Uncaught TypeError: Cannot read property 'split' of undefined
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Envuelva el texto en ` (comillas invertidas) en lugar de comillas simples ' , luego puede abarcar varias líneas.

 var myString = `abc def ghi`;
over 4 years ago · Santiago Trujillo Report

0

la respuesta aceptada funciona solo si queremos agregar \n en nuestra cadena, si solo queremos que el contenido esté en una nueva línea sin agregar \n en la cadena larga, agregue \ al final de cada línea como esta

 string firstName = `this is line 1 \ and this is line 2 => yet "new line" are not \ included because they were escaped with a "\"`; console.assert(firstName == 'this is line 1 and this is line 2 => yet "new line" are not included because they were escaped with a "\"'); // true

Nota: asegúrese de no agregar tabulaciones ni espacios al comienzo de la siguiente línea (la segunda en el ejemplo).

over 4 years ago · Santiago Trujillo Report

0

const multiLineString = [ "I wish, ", "There was a better way to do this!" ].join();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!