WilloPillow WilloPillow - 1 month ago 19
Javascript Question

Angular 2 ngModel not working ( javascript only )

So I'm a newbie on Angular2(javascript) and I was able to make a simple "Hello world" with the angular 5 min tutorial. And I was curious of the new changes on Angular2 I start reading the Angular2 Js docs but I found that it was incomplete(sucks), so I started playing around, and I got stuck on two way binding. It always returns undefined

My current script:

( function(app) {
app.TestComponent =
ng.core.Component({
selector: 'test-comp',
template: '<input ([ngModel])="name"><input type="button" (click)="click()" value="click">'
}).Class({
constructor: function(){},
click: function(){ console.log(this.name) }
})
})

(function(app) {
app.AppModule =
ng.core.NgModule({
imports: [
ng.platformBrowser.BrowserModule
],
declarations: [ app.TestComponent ],
bootstrap: [ app.TestComponent ]
})
.Class({
constructor: function() {}
});
})(window.app || ( window.app = {} ));


Whats puzzling me is there are no errors. Which makes it more difficult to Identify whats causing the undefined. Help!

Answer

It has to be

[(ngModel)]

not

([ngModel])

It's called banana in a box for a reason ;-)

Comments