![]() An important side note is that because of the way that it looks up a reference, if that reference is not defined and it can't find ref.value, when you try and run this, you'll now get an error telling you that it cannot find this. ![]() To add that, I'm going to say I want an event listener on keyup here and we'll get more into this syntax in a second, but when I refresh now, and I start typing "J-O-H-N," you can see it works just fine. That whole concept of watchers has changed quite drastically as well, using a new concept called zones, which looks for addEventListener to be added somewhere on your project. Now, if I refresh here and I start typing, nothing will happen because it hasn't set up any watchers. Then you bind to ref.value, meaning, look at this input and grab the value, because this ref is pointing to that input. If you want a value off this input, I say, hey, I want a reference to this input, I'll just use the pound sign and "ref," you could name that anything. Angular 2, on the other hand, treats this quite a bit differently, because instead of ngModel, you now work with the elements and their values themselves. If your name ever changed by this input changing, then this would also update. You bound to your name, so it set up this your name property on the scope, and then set up a watcher. Angular 1's "Hello World" example looked exactly like this, where you created an ngModel and it had a your name property. Disclaimer, Angular 2 is a work in progress and many things can and will change.
0 Comments
Leave a Reply. |