This is the 'AngularJS - seven steps from novice to expert,' the third in the series. In the first chapter, we show how to begin to build a AngularaJS applications. The second we discuss the scope and $ scope of functions. Through this entire series of tutorials, we will develop an NPR (National Public Radio) broadcast audio player that can display the latest broadcast on Morning Edition story now in the program, and play in our browser. Complete version of the Demo can be seen here. The third part of the data is bound by a text input box bound to the person.name property, our application will be able to become a little more interesting. This step is to establish a two-way binding text entry box with the page. In this context in the 'two-way' means that if you view the property values change, model will 'see' the change, and if the model changes the attribute values, view, will also 'see' the change. Angular.js good for you automatically build this mechanism. If you're curious about is how to achieve this specific, then look at our launch article, which discussed in depth digest_loop operation. To create this bind, we use ng-model instruction property on the text input box, like this: \u0026 lt; div ng-controller = \u0026 quot; MyController \u0026 quot; \u0026 gt; \u0026 lt; input type Nike Free Run 3 = \u0026 quot; text \u0026 quot; ng-model = \u0026 quot; person.name \u0026 quot; placeholder = \u0026 quot; Enter your name \u0026 quot; / \u0026 gt; \u0026 lt; h5 \u0026 gt; Hello {{person.name}} \u0026 lt; / h5 \u0026 gt; \u0026 Air Max 2011 Womens Purple Grey lt; / div \u0026 gt; now we have established good a data binding (yes, It's that easy), to see how to change the model view it: Try: When you enter in the text box, the following names are automatically changed, which shows the direction of our data binding: from view to model. We can also change the model in our (client) background, Nike Free Run 3 Women see this change is automatically reflected in the front. To demonstrate this process, let us write MyController the model a timer function, a data update on the $ scope. The following code, we have to create the timer function, it will be timed per second (like clockwork as), and update the clock on the variable data $ scope: app.controller ('MyController', function ($ scope) { $ scope.person = {name: \u0026 quot; Ari Lerner \u0026 quot;}; var updateClock = function () {$ scope.clock = new Date ();}; var timer = setInterval (function () {$ scope $ apply (updateClock. );}, 1000); updateClock ();}); You can see that when we change the data model of the clock variables, view is automatically updated to reflect this change. Braces we can simply let the value of clock variable is displayed in view in: \u0026 lt; div ng-controller = \u0026 quot; MyController \u0026 quot; \u0026 gt; \u0026 lt; h5 \u0026 gt; {{clock}} \u0026 lt; / h5 \u0026 gt; \u0026 lt; / div \u0026 gt ; see: {{clock}} Interactive Data Binding in front of us on the text entry box. Please note that the data binding is not limited to only the data, we can also use bound call $ scope of functions (already mentioned this before). Pair of buttons, links, or any other DOM element, Nike Free Run 3 Women we can use another command properties to achieve binding: ng-click. This ng-click mouse click event instruction DOM elements (ie mousedown browser events) bound to a method, when a browser on the DOM element triggers mouse click events, this method is bound to be called. To keep up with an example similar to this binding code is as follows: \u0026 lt; div ng-controller = \u0026 quot; DemoController \u0026 quot; \u0026 gt; \u0026 lt; h4 \u0026 gt; The simplest adding 586590-300 Nike Kobe 8 System Elite GC Poison Green Superhero Outlet machine ever \u0026 lt; / h4 \u0026 gt; \u0026 lt; button ng-click = \u0026 quot; add ( 1) \u0026 quot; class = \u0026 quot; button \u0026 quot; \u0026 gt; Add \u0026 lt; / button \u0026 gt; \u0026 lt; button ng-click = \u0026 quot; subtract (1) \u0026 quot; class = \u0026 quot; button \u0026 quot; \u0026 gt; Subtract \u0026 lt; / button \u0026 gt; \u0026 lt; h4 \u0026 gt; Current count: {{counter}} \u0026 lt; / h4 \u0026 gt; \u0026 lt; / div \u0026 gt; either button or link will be bound to the controller that contains them DOM elements on every $ scope objects, when they are a mouse click, Angular would call the appropriate method. Note that when we tell Angular To call what method we will string the method name written inside quotation marks. app.controller ('DemoController', function ($ scope) {$ scope.counter = 0; $ scope.add = function (amount) {$ scope.counter + = amount;}; $ scope.subtract = function (amount) {$ scope.counter - = amount;};}); see: data binding and AJAX interactive myApp in the previous example, the view of a button we were just learned data binding, to play the PlayerController the play button bindings methods (same, back stop the stop button binding method). AJAX In the last tutorial, we refer to the audio files stored on a local, it gives us a static NPR file instead of a dynamic 597806-400 Nike LeBron X EXT QS Denim-Pink Outlet NPR feed. NPR in our applications, we will populate the list with $ http to our news file playable. Angular.js native support for AJAX, thus we have gained the ability with one or more servers send requests back and forth. The ability of such a client application that we want to create is crucial, because this application requires the exchange with the server, access and update data. Angular.js by a service support AJAX (In later chapters we will discuss this service), this service is called $ http services. All Angular.js core services are using $ prefix, this point before the $ scope service where we've seen. The $ http service is extremely flexible and gave us a number of ways to Air Jordan Outlet call the AJAX service. To ensure this tutorial easy Air Jordan Heel to understand, we focus on the easiest way. After more advanced sections we will introduce further $ http services. Before delving into too much detail, let us first create a service request with $ http: $ http ({method: 'JSONP', url: 'http://api.openbeerdatabase.com/v1/beers.json?callback= JSON_CALLBACK '}). success (function (data, status, headers, config) {// data contains the response // status Nike Free Run 3 Women is the HTTP status // headers is the header getter function // config is the object that was used to create the HTTP request}) error (function (data, status, headers, config) {}); Try:. $ http Angular.js service is one of the core services, and it helps us through the XMLHttpRequest object or JSONP and remote HTTP services exchange. Note that as intact as in the example above plus the following string callback = JSON_CALLBACK, Angular.js you will be responsible for handling JSONP request, will replace JSON_CALLBACK into an appropriate callback function. $ Http service is a function: it accepts a set target, which specifies how to create HTTP requests; it returns a commitment (* The JavaScript programming promise asynchronous mode), which provides two methods: success methods Nike Lebron 10(X) and error method. To obtain a list of audio Nike Air Max files can be played, so we send a request to NPR's API. First, you need to register in order to obtain a pour NPR API key. Http://www.npr.org/templates/reg/ go to their website. (Author here with Angular.js do a load of NPR with iFrame registration form, see below, or go directly to the original English text view). Write down your API key, we need it soon. Now we want to set our PlayController to call $ http service, retrieve the audio files. Just like we do, let us call the $ http services to create a request, this time in 585388-083 Anti-Nerf Nike KD V Elite Outlet order to obtain all the audio files. We want the service to start when controller is instantiated, so we just need to put this method directly in the controller function (this function will be called when the controller is created), like this: var apiKey = 'YOUR_KEY', nprUrl = 'http://api.npr.org/query?id=61\u0026amp;fields=relatedLink,title,byline,text,audio,image,pullQuote,all\u0026amp;output=JSON';app.controller('PlayerController', function ($ scope, $ http) {// Hidden our previous section's content // construct our http request $ http ({method: 'JSONP', url: nprUrl + '\u0026 amp; apiKey =' + apiKey + '\u0026 amp; callback = JSON_CALLBACK . '}) success (function (data, status) {// Now we 2015 Nike Free 5.0 have a list of the stories (data.list.story) // in the data object that the NPR API // returns in JSON that looks like: / / data: {\u0026 quot; list \u0026 quot ;: {// \u0026 quot; title \u0026 quot ;: ... // \u0026 quot; story \u0026 quot ;: [// {\u0026 quot; id \u0026 quot ;: ... // \u0026 quot; title \u0026 quot ;: ...} ) .error (function (data, status) {// Some error occurred}); now we have a list of audio files in a function where data success;}). The success callback function, this list is stored in $ scope objects, so we simply put it in a bind on $ scope objects:. // From above}) success (function (data, status) {// Store the list of stories on the scope // from the NPR API response object (described above) $ scope.programs = data.list.story;.}) error (function (data, status) {// Some error occurred now, with Just the same, just visit programs in view, we will be able to access the data in the view where you see, it is one of the benefits of using Nike Dunk Heels Angular.js, when the commitment mode and return to a successful result, Angular.js will automatically put the result fill into your view in the \u0026 lt; div ng-controller = \u0026 quot; PlayerController \u0026 quot; \u0026 gt; {{programs}} \u0026 lt; / div \u0026 gt; try: In the next chapter, we will discuss how meaningful in our view miles Show the data objects, using some Angular.js carrying instructions (and a little more what) in this series can be downloaded from the Nike Lebron 10(X) official code base on github:. https: //github.com/auser/ng-newsletter-beginner . -series To save this code libraries to local, make sure to install the git, clone this code library, then check out one of the part3 branch: git clone https://github.com/auser/ng-newsletter-beginner- series.gitgit checkout -b part3seven steps from novice to expert Angular.JS (3): data binding and AJAX