Angular2: Promise Rejection: Quotes cannot be used for evaluation in this component

I'm currently working on a component in Angular that includes an input parameter:

import {Component, Input} from '@angular/core';

@Component({
    selector: 'comment',
    template: `    
        <div class="col-lg-6 col-md-6 col-xs-6 thumb">
            <div class="post-owner">
                <div class="media">
                    <div class="media-left">
                        <a href="#">
                          <img class="media-object rounder" [src]="imageURI" >
                        </a>
                    </div>
                </div>
            </div>
        </div>`
})

export class CommentCompoent {
    @Input() imageURI = "";
}

In the parent component, I passed an image path to it like this:

<comment [imageURI]='image_path'></comment>

However, when I run it, it gives me an error message:

EXCEPTION: Error: Uncaught (in promise): Quotes are not supported for evaluation!

Any suggestions on how to resolve this issue?

Update: Removing [imageURI]='image_path' in the parent component solved the problem and displayed the rest of the component perfectly.

Answer №1

To make the necessary changes in your parent component, update the comment tag as follows:

<comment [imagePath]="image_source"></comment>

Remember to avoid using single quotes for template bindings. Save them for string formatting only, like so:

<comment [imagePath]="'path/to/image.png'"></comment>

Answer №2

If you happen to come across this error while searching on Google, know that it lacks any useful information and can be triggered for various reasons. I encountered a similar issue where deciphering the problem solely through the HTML was challenging. However, by setting a breakpoint in the angular file being loaded in your browser (specifically compiler.umd.js, at line 11702), as highlighted in expression_converter.ts within the @angular/compiler module, at line 395, within the visitQuote() function which is responsible for throwing the exception, you can delve into the ast parameter. This parameter contains crucial properties like location and uninterpretedExpression, aiding in pinpointing the component and expression causing the error. In my case, the culprit was missing curly braces around an ngClass parameter.

Answer №3

After searching for the solution, I have found it within my parent component: The correct structure to use is

<comment [imageURI]=image_path></comment>
export class SinglePictureComponent{
    username='Salman kkk';
    profile_pic="https://scontent-arn2-1.cdninstagram.com/t51.2885-19/s150x150/13743117_1060048037418472_411027981_a.jpg";
    comment="I love you";
}

Next step is to assign the properties like this:

 <comment [username]=username   [comment]=comment [imageURI]=profile_pic></comment>

Answer №4

Recently, I encountered a similar error that looked like this:

https://i.sstatic.net/KeOt2.jpg

The faulty HTML code was:

<div class="container">
  <span class="value">{{action.progress}}</span>
   <div class="wrap">
    <div class="bar" style="{{width:action.progress}}"></div>
  </div>
</div>

After some troubleshooting, I found the solution below fixed the issue for me. The action is retrieved from a .ts file and since it should be styled using [ngStyle], we can directly pass the item value.

<div class="container">
  <span class="value">{{action.progress}}</span>
  <div class="wrap">
    <div class="bar" [ngStyle]="{width:action.progress}"></div>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Implementing a Delay in an Angular 4+ AsyncValidator with the Use of RxJS 6

I am currently grappling with the interpretation of this article, but due to recent updates in RxJS, the syntax I require seems to have changed. There is a particular aspect that eludes me. The existing validate method within my AsyncValidator appears as f ...

Get the dynamic type as the return value in a TypeScript abstract class method with generic type T

Within my codebase, I have created an abstract class: export abstract class Filters<P> { protected field: string; protected constructor(field: string) { this.field = field; } protected abstract getFilter(): P; } Additionally, there is ...

Dealing with a series of challenging npm problems consecutively

npm WARNING: Deprecated Usage Please note that global '--global' and '--local' configurations are now deprecated. Please use '--location=global' instead. Error Code: ERESOLVE Unable to resolve dependency tree. While reso ...

Discovering identical objects in two arrays in Angular using TypeScript is a breeze

I've hit a roadblock with a TypeScript problem in my Angular service. I have an array of ingredients: private ingredients: Ingredient[] = [ new Ingredient('farina', 500), new Ingredient('burro', 80), new Ingredient('ucc ...

How to refresh a page in Angular Typescript to wait for HTTP calls from the backend

Looking at the code snippet below: The initial HTTP call retrieves multiple IDs of orderlines (items). For each ID, another HTTP call is made to reserve them. Afterward, the page needs to be updated to display the reserved items. When dealing with a larg ...

What is the process for interpreting the status code retrieved from an HTTP Post request?

When sending a POST request to a backend and attempting to read the status code, I encountered the following result: status-code:0 Below are my functions: Service: signIn(uname:string, pass:string): Observable<any> { let headers = new Headers( ...

Transform Loopback 4 filter into a SQL WHERE condition

When using Loopback 4, the filter object that is received by functions like Get and Count appears as shown below: { where: { property: { op: value; } } } I am interested in converting this structure into an SQL WHERE clause to use it in ...

Please optimize this method to decrease its Cognitive Complexity from 21 to the maximum allowed limit of 15. What are some strategies for refactoring and simplifying the

How can I simplify this code to reduce its complexity? Sonarqube is flagging the error---> Refactor this method to reduce its Cognitive Complexity from 21 to the allowed 15. this.deviceDetails = this.data && {...this.data.deviceInfo} || {}; if (th ...

Encountering a problem with indexing when attempting to include dynamic input text within a form in Angular 6

Whenever I click the "Add" button, a dynamic input text box is added to the form. However, if I remove any input box (except for the last one), the second-to-last input box becomes empty. I'm not sure what the issue might be. Here is the HTML section ...

Verify the anticipated URL and showcase the real URL

During a functional test, I am attempting to create a "Then" step where the current URL is verified. After researching on SO, it appears that the proper approach is to wait for the URL to match the expected one: Then('The URL contains {string}' ...

"Encountering issues with the production build of angular2-flash-messages

I have integrated angular2-flash-messages into my Angular (4) application. I included it in app.module.ts as shown below: import { FlashMessagesModule } from 'angular2-flash-messages'; imports: [ FlashMessagesModule, ], Everything works f ...

Enhancing Apollo Cache Updates using TypeScript null checks

Currently, I am utilizing apollo codgen to automatically generate types for my graphql queries in TypeScript. However, I have noticed that the generated types contain numerous instances of null values, leading to an abundance of if checks throughout my cod ...

Managing Geolocation in Ionic2 presenting challenges

Attempting to utilize Geolocation in ionic2 for device location access. Referred to the official documentation on https://ionicframework.com/docs/native/geolocation/. Successfully installed the necessary packages: $ ionic plugin add cordova-plugin-geoloca ...

Injecting Dependencies into an Angular 6 Service

Within my typescript file, I have a collection stored in an array. component.ts list: any[]; constructor( private listProcessor: ListProcessor ) {} ngOnInit() { this.listProcessor.getListItems() .subscribe( res => { th ...

Insert an ellipsis within the ngFor iteration

I'm currently working with a table in which the td elements are filled with data structured like this: <td style="width:15%"> <span *ngFor="let org of rowData.organization; last as isLast"> {{org?.name}} ...

Steps to add annotations to a class descriptor:

Can you help me with the correct way to annotate this piece of code? export class TestCls { static SomeStaticFn(): TestCls { // Do some stuff... // Return the class descriptor for a "fluid usage" of SomeStaticFn return TestCls ...

Encountering an error in an Angular 4 application when running in Internet Explorer 11: "Unable to execute code from a script that has been freed

I am encountering an issue with my Angular app, which I believe is running version 4. The problem arises in Internet Explorer 11 during a login sequence and the error message states "Can't execute code from a freed script". The IE console points to li ...

End the pipeline execution in a chain of RxJS observables

Here is a scenario where a series of Observables are chained together. Is it possible to prevent the subsequent chain from executing if an error is thrown by 'parentObs1'? import { throwError } from "rxjs"; import { mergeMap, catchError ...

A more concise validation function for mandatory fields

When working on an HTML application with TypeScript, I encountered a situation where I needed to build an error message for a form that had several required fields. In my TypeScript file, I created a function called hasErrors() which checks each field and ...

What is the best way to execute operations on two distinct datasets within a single function using RxJS?

Is there a way to perform operations on two separate data collections within a single function in RxJS, returning an observable instead of void? This function is located within a service and I intend to subscribe to it from my component. I believe some re ...