2

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!

1 Answer 1

2

It has to be

[(ngModel)]

not

([ngModel])

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

Sign up to request clarification or add additional context in comments.

3 Comments

Okay now I got this error "Can't bind to 'ngModel' since it isn't a known property of 'input". Any Ideas? Thanks!
You need to add FormsModule to the module imports
FormsModule fixed it! Thanks, Have a great day :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.