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?
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 -> [] .
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With