Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't bind to 'ngModel' since it isn't a known native property or known directive

Tags:

angular

dart

I am trying to learn angular2dart and follow the tutorial from anguar2dart site.

Consider following code:

import 'package:angular2/core.dart';

class Hero {
  final int id;
  String name;
  Hero(this.id, this.name);
}

@Component(
    selector: 'my-app',
    template: '''
      <h1>{{title}}</h1>
      <h2>{{hero.name}} details!</h2>
      <div><label>id: </label>{{hero.id}}</div>
      <div>
        <label>name: </label>
        <input [(ngModel)]="hero.name" placeholder="name">
      </div>'''
)
class AppComponent {
  String title = 'Tour of Heroes';
  Hero hero = new Hero(1, 'Windstorm');
}

When I compiled this, it shows me the error message:

Build error:
Transform TemplateCompiler on Sample|lib/app_component.ng_meta.json threw error: Template parse errors:
Can't bind to 'ngModel' since it isn't a known native property or known directive. Please fix typo or add to directives list. ("
      <div>
        <label>name: </label>
        <input [ERROR ->][(ngModel)]="hero.name" placeholder="name">
      </div>"): AppComponent@5:15

What am I doing wrong?

like image 942
softshipper Avatar asked Oct 31 '16 15:10

softshipper


People also ask

Can't bind to ngModel since it isn't a known property of select Angular 9?

Your ngModel is not working because it's not a part of your NgModule yet. You have to tell the NgModule that you have authority to use ngModel throughout your app, You can do it by adding FormsModule into your app. module. ts -> imports -> [] .

Can't bind since it isn't a known property?

What does "Can't bind to 'x' since it isn't a known property of 'y'" mean? link. This error often means that you haven't declared the directive "x" or haven't imported the NgModule to which "x" belongs. Perhaps you declared "x" in an application submodule but forgot to export it.

Can't bind to NG value since it isn't a known property of input?

Fix this Error To get rid of this error you will have to import the FormsModule class in your app. module. ts file, followed by updating your @NgModule() decorator. Now check your browser.

Can't bind to ngModel since it isn't a known property of P calendar?

If 'p-calendar' is an Angular component and it has 'ngModel' input, then verify that it is part of this module. 2. If 'p-calendar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule. schemas' of this component to suppress this message.


1 Answers

It seems you are missing transformers for common directives in your pubspec.yaml file.

Check https://github.com/angular-examples/toh-1/blob/master/pubspec.yaml it contains following transformers angular section:

transformers:
- angular2:
    platform_directives:
    - 'package:angular2/common.dart#COMMON_DIRECTIVES'
    platform_pipes:
    - 'package:angular2/common.dart#COMMON_PIPES'
    entry_points: web/main.dart
like image 117
Dafe Šimonek Avatar answered Oct 05 '22 23:10

Dafe Šimonek