Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use rating attribute Type 'string' is not assignable to type 'number' when strict templates is enabled #7

Open
renomi opened this issue Jun 28, 2021 · 2 comments

Comments

@renomi
Copy link

renomi commented Jun 28, 2021

Hey there, thanks for the great component!

If tsconfig.app.json has

"angularCompilerOptions": {
    "strictTemplates": true
  }

And inside any page add the following:

 <ionic-rating-component #rating activeColor="#FFC200" halfStar="true" rating="0"
          (ratingChanged)="onRatingChange($event)">
  </ionic-rating-component>

Running ionic serve will fail with Type 'string' is not assignable to type 'number'.

ionic info:

Ionic:

   Ionic CLI                     : 6.16.3 (/home/dhanarenomi/.nvm/versions/node/v14.16.1/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.6.5
   @angular-devkit/build-angular : 12.0.2
   @angular-devkit/schematics    : 11.2.10
   @angular/cli                  : 11.2.10
   @ionic/angular-toolkit        : 3.1.1

Capacitor:

   Capacitor CLI      : 2.4.7
   @capacitor/android : 2.4.7
   @capacitor/core    : 2.4.7
   @capacitor/ios     : not installed

Utility:

   cordova-res : 0.15.3
   native-run  : not installed globally

System:

   NodeJS : v14.16.1 (/home/dhanarenomi/.nvm/versions/node/v14.16.1/bin/node)
   npm    : 6.14.12
   OS     : Linux 5.11
@jcancig
Copy link
Member

jcancig commented Jun 28, 2021

Hello @renomi , try with this

<ionic-rating-component #rating activeColor="#FFC200" halfStar="true" _[rating]="0"_
          (ratingChanged)="onRatingChange($event)">
</ionic-rating-component>

Another option is to declare a type number variable in the controller:

rate-page.ts

…..
rate : number = 0;
…..
export class RatePage {

    constructor() {
        
    }
}

rate-page.html

<ionic-rating-component #rating activeColor="#FFC200" halfStar="true" rating="{{number}}"
          (ratingChanged)="onRatingChange($event)">
</ionic-rating-component>

@1nstinct
Copy link

1nstinct commented Jun 6, 2022

Having the same issue. For me as a tmp workaround - remove default value. Disabling strictTemplate for entire project is not a solution for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants