<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	 xmlns:media="http://search.yahoo.com/mrss/" >

<channel>
	<title>angularjs &#8211; Codemotion</title>
	<atom:link href="https://codemotion.us/tag/angularjs/feed/" rel="self" type="application/rss+xml" />
	<link>https://codemotion.us</link>
	<description>NodeJS, AngularJS, Meteor, Javascript outsourcing Ukraine</description>
	<lastBuildDate>Tue, 18 Dec 2018 22:24:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://codemotion.us/wp-content/uploads/2023/08/CDM-Logomark-Small.png</url>
	<title>angularjs &#8211; Codemotion</title>
	<link>https://codemotion.us</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Writing Services in Angular.js</title>
		<link>https://codemotion.us/writing-services-angular-js/</link>
		
		<dc:creator><![CDATA[Yaroslav Golovach]]></dc:creator>
		<pubDate>Mon, 11 Sep 2017 15:28:01 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[the javascript]]></category>
		<guid isPermaLink="false">https://codemotion.ninja/?p=5084</guid>

					<description><![CDATA[<p>Series &#8220;Developing applications on single-Angular.js&#8221; Why do I need Angular.js and why he Modern tools and framework Angular.js frontend applications Familiarity with controllers and directives Angular.js Writing Services in Angular.js Routing in Angular.js How to connect to the API backend Angular.js In a previous article, we have recovered a list of transactions and added the [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/writing-services-angular-js/">Writing Services in Angular.js</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Series &#8220;Developing applications on single-Angular.js&#8221;</h2>
<ol>
<li><a href="https://codemotion.ninja/blog/development/why-do-i-need-angular-js">Why do I need Angular.js and why he</a></li>
<li><a href="https://codemotion.ninja/blog/development/modern-tools-framework-angular-js-frontend-applications">Modern tools and framework Angular.js frontend applications</a></li>
<li><a href="https://codemotion.ninja/blog/development/familiarity-controllers-directives-angular-js">Familiarity with controllers and directives Angular.js</a></li>
<li>Writing Services in Angular.js</li>
<li><a href="https://codemotion.ninja/blog/development/routing-angular-js">Routing in Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/connect-api-backend-angular-js">How to connect to the API backend Angular.js</a></li>
</ol>
<p>In a <a href="https://codemotion.ninja/blog/development/familiarity-controllers-directives-angular-js">previous article</a>, we have recovered a list of transactions and added the ability to add new transaction. However, as we have seen it is not related to transactions in the sidebar of our application, the total amount of money. In fact, it&#8217;s just text, registered in the html code.</p>
<p>In this article we will look at service facilities available in Angular.js. We will use the services as a single place for access to our transactions, which will allow us to get the data in different controllers. As we look at Dependency Injection in Angular.js.</p>
<p>In Angular.js available whole zoo of different types of service facilities. The most popular of these are the <code>factory</code> and <code>service</code>. Each service is a singleton, that is, there is only one instance of a particular service. It fits perfectly in our terms and conditions: a single point of access to transactions, available from any of the controllers.</p>
<p>Today we are going to use <code>factory</code>, and soon you will understand why.</p>
<p>Let&#8217;s start by adding a new file: <code>src/components/transactions_store.service.js</code> with the following content:</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">// src/components/transactions_store.service.js
angular.module('ngmkdev').factory('TransactionsStore', function() {
  return {
    transactions: []
  }
});</pre>
<p>Unlike the controllers, with the services we have more freedom in choosing the name. In this case, <code>TransactionsStore</code> makes sense, because the service will store all of the current transaction.</p>
<p>Now we need to combine this service with <code>TransactionsCtrl</code>. In Angular.js pattern used Dependency Injection. The framework itself is able to resolve the required dependencies, the developer only needs to specify the name of the component that is needed other component applications. It looks to specify dependencies as follows:</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">// src/app/main/transactions.controller.js
angular.module('ngmkdev').controller('TransactionsCtrl', function($scope, TransactionsStore) {
  // ...
});</pre>
<p>Now we have access to our service from the controller for the transaction. Since we used the factory, when you call <code>TransactionsStore</code> function is called from the definition of this service, so we can easily get all the transactions and write their controller attributes as follows:</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">// src/app/main/transactions.controller.js
angular.module('ngmkdev').controller('TransactionsCtrl', function($scope, TransactionsStore) {
  this.transactions = TransactionsStore.transactions;
  // ...
});</pre>
<p>Note that the rest of the code remains the same &#8211; Angular.js takes care of the communication controller attribute <code>transactions</code> and service upgrade.</p>
<p>Now we verify functionality in our service. We perform a number of operations are already familiar:</p>
<p>Add a new controller <code>src/app/main/navigation.controller.js</code>, in charge of the side menu in your application:</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">// src/app/main/navigation.controller.js
angular.module('ngmkdev').controller('NavigationCtrl', function(TransactionsStore) {
  this.transactions = TransactionsStore.transactions;
});</pre>
<p>We define it on the sidebar and derive the number of transactions in the parentheses after the item Transactions:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;!-- src/index.html --&gt;

&lt;!-- ... --&gt;
&lt;div class="col-xs-2" ng-controller="NavigationCtrl as navigation_ctrl"&gt;
  &lt;h2&gt;Money&lt;/h2&gt;
  &lt;h3 class="money-ok"&gt;
    500.0
  &lt;/h3&gt;
  &lt;ul class="nav nav-pills nav-stacked"&gt;
    &lt;li&gt;
      &lt;a href="#"&gt;
        &lt;i class="glyphicon glyphicon-th-list"&gt;&lt;/i&gt;
        Transactions &lt;span class="badge"&gt;{{navigation_ctrl.transactions.length}}&lt;/span&gt;
      &lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;a href="#"&gt;&lt;i class="glyphicon glyphicon-tasks"&gt;&lt;/i&gt; Settings&lt;/a&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
&lt;!-- ... --&gt;</pre>
<p>Reload the page in the browser (if gulp still has not done so) and try to add a transaction. In addition to updating the table with the transaction is automatically updated and the counter transactions in the sidebar.</p>
<p>Commit all changes, as always, in a project repository on the GitHub: <a href="https://github.com/mkdev-me/ng.mkdev/commit/6d661c0a5ecbbab2098490df23e5a2e9130f2564" target="_blank" rel="nofollow noopener">6d661c0</a></p>
<p>Homework ( <a href="https://github.com/mkdev-me/ng.mkdev/commit/d6051f50878a65a1645cb7539b9e639afc33513c" target="_blank" rel="nofollow noopener">tips</a> ):</p>
<p>Replace static amount of transactions in the sidebar to the present.<br />
Hide the table if you do not have any transactions</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/writing-services-angular-js/">Writing Services in Angular.js</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></content:encoded>
					
		
		
		
	</item>
		<item>
		<title>Routing in Angular.js</title>
		<link>https://codemotion.us/routing-angular-js/</link>
		
		<dc:creator><![CDATA[Yaroslav Golovach]]></dc:creator>
		<pubDate>Mon, 04 Sep 2017 15:52:11 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[the javascript]]></category>
		<guid isPermaLink="false">https://codemotion.ninja/?p=5088</guid>

					<description><![CDATA[<p>Series &#8220;Developing applications on single-Angular.js&#8221; Why do I need Angular.js and why he Modern tools and framework Angular.js frontend applications Familiarity with controllers and directives Angular.js Writing Services in Angular.js Routing in Angular.js How to connect to the API backend Angular.js We are approaching the end of our guidance for Angular.js. There are only two [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/routing-angular-js/">Routing in Angular.js</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Series &#8220;Developing applications on single-Angular.js&#8221;</h2>
<ol>
<li><a href="https://codemotion.ninja/blog/development/why-do-i-need-angular-js">Why do I need Angular.js and why he</a></li>
<li><a href="https://codemotion.ninja/blog/development/modern-tools-framework-angular-js-frontend-applications">Modern tools and framework Angular.js frontend applications</a></li>
<li><a href="https://codemotion.ninja/blog/development/familiarity-controllers-directives-angular-js">Familiarity with controllers and directives Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/writing-services-angular-js">Writing Services in Angular.js</a></li>
<li>Routing in Angular.js</li>
<li><a href="https://codemotion.ninja/blog/development/connect-api-backend-angular-js">How to connect to the API backend Angular.js</a></li>
</ol>
<p>We are approaching the end of our guidance for Angular.js. There are only two articles: and this is another. In this we consider the <a href="https://github.com/angular-ui/ui-router" target="_blank" rel="nofollow noopener">Angular.js UI Router</a> &#8211; a library to organize navigation between different parts of our application. At the same time, we can rewrite our code so that it uses the templates, instead of storing the entire html to a single file.</p>
<p>Templates in our application are stored in <code>src/app/app_part/</code>. Under <code>app_part</code> I mean a separate part of the application. Now we only <code>main</code>, but in the future may be in the same sub-folder <code>settings</code>, <code>categories</code> and everything else. Fast forward the entire central portion containing the form to add transactions and table with transactions in <a href="https://github.com/mkdev-me/ng.mkdev/blob/master/src/app/main/transactions.html" target="_blank" rel="noopener">src/app/main/transactions.html</a> and replace it with:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;div class="col-xs-6" ui-view&gt;&lt;/div&gt;</pre>
<p>It is also necessary to remove the ui-view from above of the container level. Thus, in <code>src/index.html</code> inside the body tag in addition to the script tags we still have the following layout:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;div class="container"&gt;
  &lt;div class="col-xs-2" ng-controller="NavigationCtrl as navigation_ctrl"&gt;
    &lt;h2&gt;Money&lt;/h2&gt;
    &lt;h3 class="money-ok"&gt;
      {{navigation_ctrl.transactions_store.sum()}}
    &lt;/h3&gt;
    &lt;ul class="nav nav-pills nav-stacked"&gt;
      &lt;li&gt;
        &lt;a&gt;
          &lt;i class="glyphicon glyphicon-th-list"&gt;&lt;/i&gt;
          Transactions &lt;span class="badge"&gt;{{navigation_ctrl.transctions_store.transactions.length}}&lt;/span&gt;
        &lt;/a&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;a&gt;
          &lt;i class="glyphicon glyphicon-tasks"&gt;&lt;/i&gt; Settings
        &lt;/a&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;div class="col-xs-6" ui-view&gt;&lt;/div&gt;
&lt;/div&gt;</pre>
<p>Now we have nothing works, because we did not specify what kind of UI Router&#8217;u template output in ui-view at the root link. That&#8217;s what this library and deals with: inserts ui-view template corresponding to the application settings.</p>
<p>So, we update <code>src/app/index.js</code> :</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">'use strict';
angular.module('ngmkdev', ['restangular', 'ui.router'])
  .config(function ($stateProvider, $urlRouterProvider) {
    $stateProvider
    .state('transactions', {
      url: "/",
      templateUrl: "app/main/transactions.html"
    });
    $urlRouterProvider.otherwise('/');
  });</pre>
<p>We use the function of <code>config()</code> to configure the various <a href="https://docs.angularjs.org/guide/providers" target="_blank" rel="nofollow noopener">service providers</a> (one of the types of services), before they begin to be used in other parts of the application.</p>
<p>Here, through a chain of calls to the function <code>state()</code> on the service <code>$stateProvider</code> we specify which template to display inside the ui-view for each page. The last line, <code>$urlRouterProvider.otherwise('/');</code> said Angular&#8217;u what address to redirect the user if the requested route does not exist. Our app now again should work as before.</p>
<p><i>Few analogies for those familiar with Ruby on Rails: ui-view can be compared with the yield in rail templates and call chain <code>state()</code> &#8211; a file routes.rb.</i></p>
<p>Let&#8217;s try to add a real navigation: to link transactions led to the table with the transactions, and settings for future user settings page.</p>
<p>We update our list of routes:</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">'use strict';
angular.module('ngmkdev', ['restangular', 'ui.router'])
  .config(function ($stateProvider, $urlRouterProvider) {

    $stateProvider
    .state('transactions', {
      url: "/transactions",
      templateUrl: "app/main/transactions.html"
    })
    .state('settings', {
      url: "/settings",
      templateUrl: "app/settings/settings.html"
    })

    $urlRouterProvider.otherwise('/transactions');
  });</pre>
<p>And add the file <code>app/settings/settings.html</code> with such content:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;h2&gt;Settings&lt;/h2&gt;</pre>
<p>Now, any nonexistent path will be redirected to the page with the transaction. Try to open the following path: <code>http://localhost:3000/</code>, <code>http://localhost:3000/#/transactions</code>, <code>http://localhost:3000/#/settings</code>, <code>http://localhost:3000/#/crap</code>.</p>
<p>Sense from the manual driving bit addresses, so revive links in the sidebar. To this end, there is UI Router directive <code>ui-sref</code>, stating the name of the State (the first argument to the function state ()), which is due to open by clicking on the following link:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;li&gt;
  &lt;a ui-sref="transactions"&gt;
    &lt;i class="glyphicon glyphicon-th-list"&gt;&lt;/i&gt;
    Transactions &lt;span class="badge"&gt;{{navigation_ctrl.transctions_store.transactions.length}}&lt;/span&gt;
  &lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
  &lt;a ui-sref="settings"&gt;
    &lt;i class="glyphicon glyphicon-tasks"&gt;&lt;/i&gt; Settings
  &lt;/a&gt;
&lt;/li&gt;</pre>
<p>That&#8217;s enough to our menu earned &#8211; by clicking on the links the central part of the application changes. Commit to the changes done in the article: <a href="https://github.com/mkdev-me/ng.mkdev/commit/448daee54a90c20c9b888008afcd92b20a56a887" target="_blank" rel="nofollow noopener">448daee</a>.</p>
<p>Homework:</p>
<ul>
<li>Refer to the documentation UI Router way to highlight the current menu item</li>
</ul>
<p>The post <a rel="nofollow" href="https://codemotion.us/routing-angular-js/">Routing in Angular.js</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></content:encoded>
					
		
		
		
	</item>
		<item>
		<title>Familiarity with controllers and directives Angular.js</title>
		<link>https://codemotion.us/familiarity-controllers-directives-angular-js/</link>
		
		<dc:creator><![CDATA[Yaroslav Golovach]]></dc:creator>
		<pubDate>Mon, 31 Oct 2016 15:02:13 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[the javascript]]></category>
		<guid isPermaLink="false">https://codemotion.ninja/?p=5067</guid>

					<description><![CDATA[<p>Series &#8220;Developing applications on single-Angular.js&#8221; Why do I need Angular.js and why he Modern tools and framework Angular.js frontend applications Familiarity with controllers and directives Angular.js Writing Services in Angular.js Routing in Angular.js How to connect to the API backend Angular.js In this article we will write a simple controller Angular.js and make it display [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/familiarity-controllers-directives-angular-js/">Familiarity with controllers and directives Angular.js</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Series &#8220;Developing applications on single-Angular.js&#8221;</h2>
<ol>
<li><a href="https://codemotion.ninja/blog/development/why-do-i-need-angular-js">Why do I need Angular.js and why he</a></li>
<li><a href="https://codemotion.ninja/blog/development/modern-tools-framework-angular-js-frontend-applications">Modern tools and framework Angular.js frontend applications</a></li>
<li>Familiarity with controllers and directives Angular.js</li>
<li><a href="https://codemotion.ninja/blog/development/writing-services-angular-js">Writing Services in Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/routing-angular-js">Routing in Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/connect-api-backend-angular-js">How to connect to the API backend Angular.js</a></li>
</ol>
<p>In this article we will write a simple controller Angular.js and make it display the data in this table using the built-in Angular directives. Moreover, we revive this form so that it really adds a new row to the table transactions.</p>
<p>Controllers Angular.js are the link between the html-marking and a &#8220;model&#8221;. The Angular model responsible for just 4 different kinds of objects, which we will discuss later. Omit is that the model and will store all of the data directly in the controller.</p>
<p>The task of the controller, as well as in other MVC frameworks, is to obtain data from the model and display it to the user, or in the other direction, to obtain data from the view and sending them to the model.</p>
<p>First of all, remove <code>src/app/main.controller.js</code>, <code>src/app/main.controller.spec.js</code>, <code>src/app/main.html</code> and <code>src/components/navbar/</code>, which generated the Yeoman for us.</p>
<h4>Writing the first controller</h4>
<p>Our first controller will be called <code>TransactionsCtrl</code>. According to the naming conventions in Angular.js, controller name is constructed as a &#8220;name + Ctrl&#8221;.</p>
<p>Create a file <code>src/app/main/transactions.controller.js</code>. In this file, define the controller itself:</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">//src/app/main/transactions.controller.js
 angular. module ( "ngmkdev") . controller ( 'TransactionsCtrl', function ($ scope) {

 });</pre>
<p>Note that we do not need to connect the newly created file manually using the tag <code>&lt;script&gt;</code>. When we run <code>gulp serve</code>, Gulp will begin to monitor changes to files and folders and update the temporary <code>index.html</code> inside the folder <code>.tmp/</code> (he, by the way, and is loaded when you open the browser <code>localhost:4567</code>). And when it comes time to collect the final version of the application, the command gulp build will do the same and return to us the necessary <code>index.html</code> with pressed down or attached files, necessary libraries and applications.</p>
<p>At this stage, we will not break layout application into multiple files and directly edit src/index.html (and so we removed the folder components/navbar/ and main.html ).</p>
<p>The index.html file replace <code>&lt;div ui-view&gt;&lt;/div&gt;</code> on the following simple layout:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;!-- src/index.html --&gt;
&lt;div ui-view class="container"&gt;
  &lt;div class="col-xs-2"&gt;
    &lt;h2&gt;Money&lt;/h2&gt;
    &lt;h3 class="money-ok"&gt;
      500.0
    &lt;/h3&gt;
    &lt;ul class="nav nav-pills nav-stacked"&gt;
      &lt;li&gt;
        &lt;a href="#"&gt;&lt;i class="glyphicon glyphicon-th-list"&gt;&lt;/i&gt; Transations&lt;/a&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;a href="#"&gt;&lt;i class="glyphicon glyphicon-tasks"&gt;&lt;/i&gt; Settings&lt;/a&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;div class="col-xs-6"&gt;
    &lt;h2&gt;Transations&lt;/h2&gt;

    &lt;br&gt;
  &lt;/div&gt;
&lt;/div&gt;</pre>
<p>Note: we have not spent a single second on the manual connection Boostrap, but soon moved to its use. Many developing routine processes are automated: we only need to impose himself layout. On connecting the files will take care Gulp, and of a beautiful appearance &#8211; Bootstrap.</p>
<p>Now you need to determine the controller on some the html-element in our application to have access to the controller inside and we could use the data from the controller inside the html.</p>
<p>It is best suited for this central unit with the transaction. Define the controller on the parent unit using directives <code>ng-controller</code>:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;!-- src/index.html --&gt;
&lt;div class="col-xs-6" ng-controller="TransactionsCtrl as transactions_ctrl"&gt;
   &lt;h2&gt;Transations&lt;/h2&gt;
   &lt;br&gt;
&lt;/div&gt;</pre>
<p>Directive Angular.js responsible for adding new functionality html-markup. This directive goes through the connection of your js-code interface. <code>ng-controller</code> &#8211; one of the simplest and most important directives. She attributes part of html code to a particular controller, makes available <code>$scope</code> of this controller inside the html element.</p>
<h4>What is the $scope?</h4>
<p><code>$scope</code> &#8211; is an object, through which we can get in the html code of access to the data from the model and controller. In Angular.js implemented a complex system upgrade and inheritance Scope. The most important is the <code>$rootScope</code>, which is defined on the entire application and accessible from any part of the code. Controllers provide a <code>$scope</code>, which is available in html-element on which this controller is defined.</p>
<p>Starting with version 1.2, in Angular.js a new syntax for accessing the controller from html: specifying <code>as transactions_ctrl</code> to <code>$scope</code> of this element defines a new object corresponding to the controller. All that we define in <code>TransactionsCtrl</code> controller through <code>this</code> will be available through <code>transactions_ctrl</code>. Thus solving the problem of nested <code>$scope</code> &#8211; we always know exactly how to Scope we work.</p>
<p>Let&#8217;s see this behavior as an example. Define attribute transactions for the controller as follows:</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">//src/app/main/transactions.controller.js
angular.module('ngmkdev').controller('TransactionsCtrl', function($scope) {
  this.transactions = [
    { amount: 500.00, date: "08/08/2014", description: "Subscribe to the magazine" },
    { amount: 150.00, date: "07/08/2015", description: "Cocaine" }
  ]
});</pre>
<p>And I will bring the transaction using another directive &#8211; <code>ng-repeat</code>, responsible for the removal of the collections. Its syntax is self-explanatory.</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;!-- src/index.html --&gt;
&lt;div class="col-xs-6" ng-controller="TransactionsCtrl as transactions_ctrl"&gt;
  &lt;h2&gt;Transactions&lt;/h2&gt;
  &lt;br&gt;
  &lt;table class="table table-striped"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Sum&lt;/th&gt;
        &lt;th&gt;Date&lt;/th&gt;
        &lt;th&gt;Descriptions&lt;/th&gt;
        &lt;th&gt;Actions&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr ng-repeat="transaction in transactions_ctrl.transactions"&gt;
        &lt;td&gt;{{transaction.amount}}&lt;/td&gt;
        &lt;td&gt;{{transaction.date}}&lt;/td&gt;
        &lt;td&gt;{{transaction.description}}&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
&lt;/div&gt;</pre>
<p>To print something from the controller to the screen the user uses braces. Angular.js uses existing template engines like <a href="http://handlebarsjs.com/" target="_blank" rel="nofollow noopener">Handlebars</a> or <a href="https://mustache.github.io/" target="_blank" rel="nofollow noopener">Mustache</a>. Instead, the framework is built right into your template.</p>
<p>But of course we need &#8211; we need a way to add new transactions. To do this, we mark up a simple form, paste it immediately after the header <code>&lt;h2&gt;Transactions&lt;/h2&gt;</code>:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;!-- src/index.html --&gt;
&lt;form class="form-inline"&gt;
  &lt;div class="form-group"&gt;
    &lt;div class="input-group"&gt;
      &lt;div class="input-group-addon"&gt;$&lt;/div&gt;
      &lt;input class="form-control" type="text" placeholder="Amount"&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
    &lt;label class="sr-only"&gt;&lt;/label&gt;
    &lt;input type="text" class="form-control" placeholder="Description"&gt;
  &lt;/div&gt;
  &lt;button type="submit" class="btn btn-default"&gt;Add&lt;/button&gt;
&lt;/form&gt;</pre>
<p>Add a template for a new transaction to the controller:</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">// src/app/main/transactions.controller.js

// ...
  this.resetTransaction = function() {
    this.newTransaction = {
      amount: 0.0,
      date: "01/02/1993",
      description: null
    }
  }
  this.resetTransaction();
// …</pre>
<p>The current transaction will be equal to the workpiece from the function immediately after initialization controller <code>resetTransaction()</code>.</p>
<p>Now you need to associate the shape of the object newTransaction . To do this, we will use the directive <code>ng-model</code>, which links form element with any controller attribute. Altered INPUT take the form:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;!-- src/index.html --&gt;
&lt;!-- ... --&gt;
&lt;input class="form-control"
       type="text"
       placeholder="Amount"
       ng-model="transactions_ctrl.newTransaction.amount"&gt;
&lt;!-- ... --&gt;
&lt;input type="text"
       class="form-control"
       placeholder="Description"
       ng-model="transactions_ctrl.newTransaction.description"&gt;
&lt;!-- ... --&gt;</pre>
<p>It remains now add form submission process. Fortunately, this has a built-in Angular.js directive <code>ng-submit</code>. Form takes the form:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;!-- src/index.html --&gt;
&lt;form class="form-inline" ng-submit="transactions_ctrl.addTransaction()"&gt;
&lt;!-- ... --&gt;
&lt;/form&gt;</pre>
<p>Add a method <code>addTransaction()</code> in <code>TransactionsCtrl</code> :</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">// src/app/main/transactions.controller.js
// ...
this.addTransaction = function() {
  this.transactions.push(this.newTransaction);
  this.resetTransaction();
}
// ...</pre>
<p>&nbsp;</p>
<p>All is ready! Open the browser, fill in the form below, or Hit Enter-button on the form and our table is automatically updated: a new transaction appears at the bottom of the table. Note: we have not written the code that updates a table. Angular.js he understands that when the array of transactions need to be updated corresponding to the array of the html-code. This is one of the coolest features Angular.js &#8211; automatic updates and two-way communication between the html-code and application code.</p>
<p>Now, dear reader is invited to move from reading the tutorial to a particular practice. Here are some tasks that you can solve on their own within this sample application:</p>
<ol>
<li>Get rid of these transactions directly in the code.</li>
<li>Sort Descending transaction Transaction date &#8211; the most recent on top than below the old one.</li>
</ol>
<p>Forknite <a href="https://github.com/mkdev-me/ng.mkdev" target="_blank" rel="nofollow noopener">repository with an application</a> and implement these tasks. All the code in this article is to commit <a href="https://github.com/mkdev-me/ng.mkdev/commit/12aacf62a4b8ffb6503201ac62d74b7bb8adce81" target="_blank" rel="nofollow noopener">12aacf6</a> In the next article we will learn how to use the service objects and learn about dependency injection in Angular.js.</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/familiarity-controllers-directives-angular-js/">Familiarity with controllers and directives Angular.js</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></content:encoded>
					
		
		
		
	</item>
		<item>
		<title>Modern tools and framework Angular.js frontend applications</title>
		<link>https://codemotion.us/modern-tools-framework-angular-js-frontend-applications/</link>
		
		<dc:creator><![CDATA[Yaroslav Golovach]]></dc:creator>
		<pubDate>Mon, 31 Oct 2016 10:56:48 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[the javascript]]></category>
		<guid isPermaLink="false">https://codemotion.ninja/?p=5035</guid>

					<description><![CDATA[<p>Series &#8220;Developing applications on single-Angular.js&#8221; Why do I need Angular.js and why he Modern tools and framework Angular.js frontend applications Familiarity with controllers and directives Angular.js Writing Services in Angular.js Routing in Angular.js How to connect to the API backend Angular.js In this article, we will configure the operating environment necessary for productive work with [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/modern-tools-framework-angular-js-frontend-applications/">Modern tools and framework Angular.js frontend applications</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Series &#8220;Developing applications on single-Angular.js&#8221;</h2>
<ol>
<li><a href="https://codemotion.ninja/blog/development/why-do-i-need-angular-js">Why do I need Angular.js and why he</a></li>
<li>Modern tools and framework Angular.js frontend applications</li>
<li><a href="https://codemotion.ninja/blog/development/familiarity-controllers-directives-angular-js">Familiarity with controllers and directives Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/writing-services-angular-js">Writing Services in Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/routing-angular-js">Routing in Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/connect-api-backend-angular-js">How to connect to the API backend Angular.js</a></li>
</ol>
<p>In this article, we will configure the operating environment necessary for productive work with Angular.js. But before moving on to the review of the tools we need, let&#8217;s look at a naive solution to the problem of files and folders in the frontend application.</p>
<p>In the picture we can see the structure of the application in which all javascript files are stored in the same folder, without any division into logical components. In index.html &#8211; connecting these files bunch of tags <code>&lt;script&gt;</code>. Not get away with this approach: the files will be more and support such an application would be many times more difficult. Other developers in the project will be confused, they have each time to understand that where and how.</p>
<p><img fetchpriority="high" decoding="async" width="866" height="418" class="alignnone size-medium wp-image-5038" src="https://codemotion.ninja/wp-content/uploads/2016/10/angular-post-2-img-1.jpg" alt="angular-post-2-img-1" srcset="https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-1.jpg 866w, https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-1-300x145.jpg 300w, https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-1-768x371.jpg 768w" sizes="(max-width: 866px) 100vw, 866px" /></p>
<p>This is a problem faced by many front-end developers, and as a result wrote various insturmenty to facilitate the development process.</p>
<h4>Tools for frontend development</h4>
<p>The first of them &#8211; <a href="http://yeoman.io/" target="_blank" rel="nofollow noopener">Yeoman</a>. This is a program to generate code similar to the generators of the Ruby on Rails. Generators allow using simple commands in the console to create a new application with a specific directory structure, eliminating the need to do it manually and make it easier to follow the standards in the organization of the code. For Yeoman written many generators, including Angular.js applications ember.js applications simple applications using jQuery, etc.</p>
<p>The second tool &#8211; <a href="http://gulpjs.com/" target="_blank" rel="nofollow noopener">Gulp.js</a>. It can be compared with <a href="https://github.com/ruby/rake" target="_blank" rel="nofollow noopener">Rake</a> from Ruby world: Gulpen allows to describe the various tasks that must be performed during development: for example, the compilation of the final css and js files or automatically update the browser page after changes to these files, which saves time developer.</p>
<p>In Angular.js already built modules support, so we do not need to use tools such as <a href="http://browserify.org/" target="_blank" rel="nofollow noopener">Browserify</a> or <a href="http://requirejs.org/" target="_blank" rel="nofollow noopener">require.js</a> to manage dependencies between modules.</p>
<p>To install the Yeoman and Gulp.js we need <a href="https://www.npmjs.com/" target="_blank" rel="nofollow noopener">npm</a>. npm &#8211; is a package manager for <a href="https://nodejs.org/" target="_blank" rel="nofollow noopener">node.js</a>, which, in turn, is the engine for writing server-side javascript applications. We will use npm to install all of our dependencies in the design.</p>
<p>More we need <a href="http://bower.io/" target="_blank" rel="nofollow noopener">Bower</a> , another package manager on Twitter. Bower is designed for installation dependencies needed in the front. For example, various jQuery plugins or Angular.js library. The advantage of using Bower for these dependencies is that Bower does not download attachments based, so each library will be installed only once. It is very important for the end user &#8211; no one wants to download five versions of jQuery.</p>
<p><img decoding="async" width="835" height="278" class="alignnone size-medium wp-image-5042" src="https://codemotion.ninja/wp-content/uploads/2016/10/angular-post-2-img-2.jpg" alt="angular-post-2-img-2" srcset="https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-2.jpg 835w, https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-2-300x100.jpg 300w, https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-2-768x256.jpg 768w" sizes="(max-width: 835px) 100vw, 835px" /></p>
<h4>Generation Angular.js applications</h4>
<p>Let&#8217;s start with installing node.js and npm. If you have a Mac, you can do this by running <code>brew install node</code>. If you Ubuntu, you can install the package by using <code>apt-get install node</code>. For all installation methods, check the official website of node.js &#8211; <a href="http://nodejs.org/" target="_blank" rel="nofollow noopener">http://nodejs.org/</a>.</p>
<p>With node.js established and npm, which means we can go directly to the installation Yeoman, Gulp and Bower. This is done in the command <code>npm install yo bower gulp -g</code>. Option <code>-g</code> installs as a global package. This allows the use of command utilities for any directory on your system. Otherwise, the relationship will be downloaded in the current folder in a subfolder <code>node_modules</code>. If an error appears that Gulp is not found in the project folder, try the <code>npm link gulp</code>.</p>
<p>Now we need to install the generator to Yeoman. Instead, the official Angular.js generator we use a <a href="https://github.com/Swiip/generator-gulp-angular" target="_blank" rel="nofollow noopener">copy of it</a>, which is used Gulp. An alternative could be Gulp <a href="http://gruntjs.com/" target="_blank" rel="noopener">Grunt.js</a>. Grunt.js similar to Gulp, but slower because of the fact that it does not use node.js. flows It is also more difficult to use.</p>
<p>Perform <code>npm install -g generator-gulp-angular</code>, and thus ends the installation of the first set of a package we want.</p>
<p>Go to the application generation. Create a new folder ngmkdev and it will fulfill <code>yo gulp-angular</code>. Generator prompts us to specify the individual parameters of our application:</p>
<ol>
<li>Select the latest version of Angular.js.</li>
<li>Of the additional modules Angular.js we do not need, so skip the selection of angular-animate, angular-cookies, angular-touch and angular-sanitize.</li>
<li>Choosing jQuery 2.x. In Angular.js already built a lightweight version of jQuery &#8211; jqLite. But we may need more advanced jQuery features, so connect a full library.</li>
<li>Since we plan to work with JSON API, then we need a library for easy handling. Of the two options is most popular in the community and has more features <a href="https://github.com/mgonto/restangular" target="_blank" rel="nofollow noopener">Restangular</a> , why dwell on it.</li>
<li>For the same reasons we choose <a href="https://github.com/angular-ui/ui-router" target="_blank" rel="nofollow noopener">UI Router</a> instead of the official of the router.</li>
<li>To write your own interface, we will use <a href="http://getbootstrap.com/" target="_blank" rel="nofollow noopener">Twitter boostrap</a>. This will speed up the time for typesetting and make our application a little more beautiful.</li>
<li>Once selected Bootstrap, the future will choose the next step Angular UI Bootstrap</li>
<li>We choose the good old css at the moment.</li>
<li>Just do without CoffeeScript (we love it, but then you do not know it yet?)</li>
<li>We will use standard HTML.</li>
</ol>
<p>Note: we did not connect <a href="http://sass-lang.com/" target="_blank" rel="nofollow noopener">SASS</a> and <a href="http://coffeescript.org/" target="_blank" rel="nofollow noopener">CoffeeScript</a> exclusively to pereslozhnyat not material for newcomers to modern front-end development. If you are familiar with these tools, it is recommended that they also use within the project.</p>
<h4>Analysis of the structure of the application Angular.js</h4>
<p>On generation will leave for some time, after which we get a framework for our application. Let&#8217;s see what we have to generate.</p>
<p><b>package.json</b></p>
<p>File <code>package.json</code> contains various metadata about your project: project name, version, description.</p>
<p><code>dependencies</code> &#8211; that is an empty list of project dependencies.</p>
<p><code>devDependencies</code> &#8211; it&#8217;s dependencies required for application development. Not the fact that we will use all of the dependencies that it has generated Yeoman, but some of them are definitely useful and unnecessary can be removed afterwards.</p>
<p><code>engines</code> &#8211; indicates node.js version, we (implicitly) will use.</p>
<pre class="prettyprint lang-json" data-start-line="1" data-visibility="visible" data-highlight="4,5,41" data-caption="">{
   "Name": "ngmkdev",
   "Version": "0.0.0",
   "Dependencies": {},
   "DevDependencies": {
     "Gulp": "~ 3.8.10",
     "Gulp-autoprefixer": "~ 2.0.0",
     "Gulp-angular-templatecache": "~ 1.4.2",
     "Del": "~ 0.1.3",
     "Gulp-consolidate": "~ 0.1.2",
     "Gulp-csso": "~ 0.2.9",
     "Gulp-filter": "~ 1.0.2",
     "Gulp-flatten": "~ 0.0.4",
     "Gulp-jshint": "~ 1.9.0",
     "Gulp-load-plugins": "~ 0.7.1",
     "Gulp-size": "~ 1.1.0",
     "Gulp-uglify": "~ 1.0.1",
     "Gulp-useref": "~ 1.0.2",
     "Gulp-ng-annotate": "~ 0.3.6",
     "Gulp-replace": "~ 0.5.0",
     "Gulp-rename": "~ 1.2.0",
     "Gulp-rev": "~ 2.0.1",
     "Gulp-rev-replace": "~ 0.3.1",
     "Gulp-minify-html": "~ 0.1.7",
     "Gulp-inject": "~ 1.0.2",
     "Gulp-protractor": "~ 0.0.11",
     "Gulp-karma": "~ 0.0.4",
     "Gulp-angular-filesort": "~ 1.0.4",
     "Main-bower-files": "~ 2.4.0",
     "Jshint-stylish": "~ 1.0.0",
     "Wiredep": "~ 2.2.0",
     "Karma-jasmine": "~ 0.3.1",
     "Karma-phantomjs-launcher": "~ 0.1.4",
     "Require-dir": "~ 0.1.0",
     "Browser-sync": "~ 1.7.1",
     "Http-proxy": "~ 1.7.0",
     "Chalk": "~ 0.5.1",
     "Protractor": "~ 1.4.0",
     "Uglify-save-license": "~ 0.4.1"
   }
   "Engines": {
     "Node": "&gt; = 0.10.0"
   }
 }</pre>
<p>&nbsp;</p>
<p><b>bower.json</b></p>
<p>In <code>bower.json</code> stored dependencies for the end user. As mentioned earlier, Bower does not download attachments, depending which makes it ideal for front-end dependencies of your application. Here we see, for example, as defined above jQuery, Twitter Boostrap, Restangular.</p>
<pre class="prettyprint lang-json" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">{
  "name": "ngmkdev",
  "version": "0.0.0",
  "dependencies": {
    "jquery": "~2.1.1",
    "restangular": "~1.4.0",
    "angular-ui-router": "~0.2.13",
    "bootstrap": "~3.3.1",
    "angular-bootstrap": "0.12.x",
    "angular": "~1.3.4"
  },
  "devDependencies": {
    "angular-mocks": "~1.3.4"
  },
  "resolutions": {
    "jquery": "~2.1.1",
    "angular": "~1.3.4"
  }
}</pre>
<p>&nbsp;</p>
<p><b>gulpfile.js</b></p>
<p><code>gulpfile.js</code> only connects all the files from the folder <code>gulp/</code>. This folder contains the various tasks performed Gulp.js. For example, <code>gulp/build.js</code> collects the final application ready for use in prodakshene. We will not delve into the gulp-syntax problems, we consider it as something other time.</p>
<p><b>node_modules and bower_components</b></p>
<p>In <code>node_modules/</code> npm downloads all the dependencies of package.json. In <code>bower_components/</code> downloaded all the dependencies of bower.json.</p>
<p><b>karma.conf.js</b></p>
<p>It contains the configuration of karma &#8211; test framework Angular.js. It we also look at some other time. As to the test environment includes a folder <code>e2e/</code> (end-to-end) and <code>protractor.conf.js</code>.</p>
<hr />
<p>For all other folders, which we shall consider in the following articles, contains the application itself, and tests it.</p>
<p>Now let&#8217;s run our application and see how it looks in a browser. To do this, we need to execute the command <code>gulp serve</code> (what makes this team can be found in the file <code>gulp/server.js</code> near 34th line). Upon execution, the application automatically opens in a browser. In development mode, it will spin at <code>localhost:3000</code>.</p>
<p>Note: this also launch live reload. If you add something to the index.html, then after saving Gulp file in the browser reloads the page for us.</p>
<p>So, we have generated a framework for our project, reviewed the main application files and folders, and run it. In the next article we will start to write the application. Full application code developed within this series, is available in the GitHub: <a href="https://github.com/mkdev-me/ng.mkdev" target="_blank" rel="nofollow noopener">https://github.com/mkdev-me/ng.mkdev</a>. Each article is devoted to a separate commit to the repository.</p>
<h4>Further reading</h4>
<ul>
<li><a href="https://docs.google.com/document/d/1XXMvReO8-Awi1EZXAXS4PzDzdNvV6pGcuaF4Q9821Es/pub" target="_blank" rel="nofollow noopener">Best Practice Recommendations for Angular App Structure</a></li>
<li><a href="https://github.com/Swiip/generator-gulp-angular" target="_blank" rel="nofollow noopener">github.com/Swiip/generator-gulp-angular</a></li>
</ul>
<p>The post <a rel="nofollow" href="https://codemotion.us/modern-tools-framework-angular-js-frontend-applications/">Modern tools and framework Angular.js frontend applications</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></content:encoded>
					
		
		
		
		<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-1-150x150.jpg" />
		<media:content url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-1.jpg" medium="image">
			<media:title type="html">angular-post-2-img-1</media:title>
			<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-1-150x150.jpg" />
		</media:content>
		<media:content url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-2.jpg" medium="image">
			<media:title type="html">angular-post-2-img-2</media:title>
			<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-2-img-2-150x150.jpg" />
		</media:content>
	</item>
		<item>
		<title>Why do I need Angular.js and why he</title>
		<link>https://codemotion.us/why-do-i-need-angular-js/</link>
		
		<dc:creator><![CDATA[Yaroslav Golovach]]></dc:creator>
		<pubDate>Mon, 31 Oct 2016 09:53:56 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[the javascript]]></category>
		<guid isPermaLink="false">https://codemotion.ninja/?p=5015</guid>

					<description><![CDATA[<p>Series &#8220;Developing applications on single-Angular.js&#8221; Why do I need Angular.js and why he Modern tools and framework Angular.js frontend applications Familiarity with controllers and directives Angular.js Writing Services in Angular.js Routing in Angular.js How to connect to the API backend Angular.js Why do I need Angular.js and why he At some point, you decide to [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/why-do-i-need-angular-js/">Why do I need Angular.js and why he</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Series &#8220;Developing applications on single-Angular.js&#8221;</h2>
<ol>
<li>Why do I need Angular.js and why he</li>
<li><a href="https://codemotion.ninja/blog/development/modern-tools-framework-angular-js-frontend-applications">Modern tools and framework Angular.js frontend applications</a></li>
<li><a href="https://codemotion.ninja/blog/development/familiarity-controllers-directives-angular-js">Familiarity with controllers and directives Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/writing-services-angular-js">Writing Services in Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/routing-angular-js">Routing in Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/connect-api-backend-angular-js">How to connect to the API backend Angular.js</a></li>
</ol>
<h2>Why do I need Angular.js and why he</h2>
<p>At some point, you decide to write a web application in which everything runs on AJAX call, the page never reloads, and the interface resembles a full-fledged desktop application rather than a traditional website. You try to do everything with a simple JavaScript and jQuery plugins couple of dozen, and quickly written code will be impossible to maintain, it is impossible to read and impossible to govern.</p>
<p>To avoid such a catastrophic situation, you need a tool that provides a rigid structure of the code and agreement on writing applications, as well as turnkey solutions for known issues (for example, for two-way communication variable in the code and text on the page that displays the value of this variable). This tool &#8211; JavaScript MVC (MVC or analogs) frameworks.</p>
<p>There is a high probability that you will not need to use the JS frameworks coming months and \ or years. The area of application is quite specific: the so-called one-page application (Single Page Applications, SPA). Typical examples: Google Drive, Gmail, Evernote. But even in those cases when the task is to write a one-page application that does not always make sense to use a full-fledged JavaScript framework: it all depends on how dynamic and complex UI you are trying to build.</p>
<p>Web version of Evernote &#8211; SPA typical application</p>
<p><img decoding="async" width="328" height="170" class="alignnone size-medium wp-image-5025" src="https://codemotion.ninja/wp-content/uploads/2016/10/angular-post-1-img-1.jpg" alt="angular-post-1-img-1" srcset="https://codemotion.us/wp-content/uploads/2016/10/angular-post-1-img-1.jpg 328w, https://codemotion.us/wp-content/uploads/2016/10/angular-post-1-img-1-300x155.jpg 300w" sizes="(max-width: 328px) 100vw, 328px" /></p>
<p>Nevertheless, the popularity of such tools has never been greater, and at least be aware of their existence is. Tell all available varintah at a time is not possible, so in this series of articles we will look at a framework Angular.js. If you are interested in alternative solutions, you can watch them online <a href="http://todomvc.com/" target="_blank" rel="nofollow noopener">http://todomvc.com/</a> &#8211; the authors of the draft implementing the same application on different frameworks, to make it easier for developers to choose the most suitable for them.</p>
<h4>Why Angular.js?</h4>
<p>From my point of view, Angular.js became a stunning combination of a low entry threshold and a rich set of functions. To start writing on it a small application, you will need about an hour of free time. In this case the fact to learn and to use all its features, will need months. While there was not a single front end problems I could not solve with the help of this framework. And I used it for cross-platform mobile applications with rich functionality, small widgets within applications and even video editor.</p>
<p>Angular.js at the moment is the most popular framework, whose development is supported by the guys from Google. In addition to the rich standard library, for &#8220;angulyara&#8221; written many custom extensions, with a part of which we will introduce within this series. There is even a special framework over Angular.js, which greatly facilitates writing cross-platform mobile applications: <a href="http://ionicframework.com" target="_blank" rel="nofollow noopener">http://ionicframework.com</a></p>
<p><img loading="lazy" decoding="async" width="695" height="185" class="alignnone size-medium wp-image-5031" src="https://codemotion.ninja/wp-content/uploads/2016/10/angular-post-1-img-2.png" alt="angular-post-1-img-2" srcset="https://codemotion.us/wp-content/uploads/2016/10/angular-post-1-img-2.png 695w, https://codemotion.us/wp-content/uploads/2016/10/angular-post-1-img-2-300x80.png 300w" sizes="(max-width: 695px) 100vw, 695px" /></p>
<h4>What about Angular.js 2.0?</h4>
<p>The current version Angular.js, where this series of articles will be based &#8211; 1.3. The developers have stated that the version 2.0, which will be released when it is not known (but no earlier than year and a half), is incompatible with the current version of the framework, but it will retain most of the concepts embodied in it. Also, the developers promise to support the version 1.x for several years after the release of 2.0.</p>
<p>This means that at least another 2 years Angular.js 1.x will continue to dominate on it is still written thousands of applications and a variety of jobs (especially in Europe) indicate precisely the frameworks in the requirements. Of course, at some point you will have to spend a couple of hours trying to deal with the new version 2.0 and, most likely, a couple of days to switch from 1.x to 2.0. Nevertheless, Angular.js knowledge will not be thrown in the trash, because, as you already know, this issue is not a specific technology, and the ability to understand any of them, and apply for its task <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The announcement of version 2.0 can be read here: <a href="http://angularjs.blogspot.se/2014/10/ng-europe-angular-13-and-beyond.html" target="_blank" rel="nofollow noopener">http://angularjs.blogspot.se/2014/10/ng-europe-angular-13-and-beyond.html</a>. More good article with more technical details: <a href="http://ng-learn.org/2014/03/AngularJS-2-Status-Preview/" target="_blank" rel="nofollow noopener">http://ng-learn.org/2014/03/AngularJS-2-Status-Preview/</a></p>
<h4>So what are we going to do?</h4>
<p>In this series of articles we will write a small finance manager: start with the work environment configuration and structure of the project and will finish the work with the API. On the way to get acquainted with the basic concepts Angular.js, routing, some third-party libraries, and a few essential tools of modern front-end development. At the end of the series, you should be able to write a simple application to Angular.js and know where to look in order to learn how to develop more complicated things.</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/why-do-i-need-angular-js/">Why do I need Angular.js and why he</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></content:encoded>
					
		
		
		
		<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-1-img-1-150x150.jpg" />
		<media:content url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-1-img-1.jpg" medium="image">
			<media:title type="html">angular-post-1-img-1</media:title>
			<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-1-img-1-150x150.jpg" />
		</media:content>
		<media:content url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-1-img-2.png" medium="image">
			<media:title type="html">angular-post-1-img-2</media:title>
			<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-1-img-2-150x150.png" />
		</media:content>
	</item>
		<item>
		<title>5 reasons for Angular-makers in favor of using Meteor</title>
		<link>https://codemotion.us/5-reasons-angular-makers-favor-using-meteor/</link>
		
		<dc:creator><![CDATA[Yaroslav Golovach]]></dc:creator>
		<pubDate>Wed, 26 Oct 2016 16:55:50 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[angular-meteor]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[meteorjs]]></category>
		<guid isPermaLink="false">https://codemotion.ninja/?p=5112</guid>

					<description><![CDATA[<p>If you have not heard of the Meteor, that&#8217;s just the time has come to explore. Meteor provides you with real-time support for the regime in your applications, as well as providing full-stack development environment for javascript / nodejs. This platform is the most &#8220;star&#8221; among nodejs-frameworks (also included in the 10 most &#8220;star&#8221; repository [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/5-reasons-angular-makers-favor-using-meteor/">5 reasons for Angular-makers in favor of using Meteor</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you have not heard of the Meteor, that&#8217;s just the time has come to explore. Meteor provides you with real-time support for the regime in your applications, as well as providing full-stack development environment for javascript / nodejs. This platform is <a href="http://nodeframework.com/" target="_blank" rel="nofollow noopener">the most &#8220;star&#8221; among nodejs-frameworks</a> (also <a href="https://github.com/search?q=stars:%3E1&amp;s=stars&amp;type=Repositories" target="_blank" rel="nofollow noopener">included in the 10 most &#8220;star&#8221; repository on Github</a>). So what do all these people do wrong?</p>
<p>Adding <a href="https://www.angular-meteor.com/" target="_blank" rel="nofollow noopener">Angular-Meteor</a> support, Meteor will be a great addition for Angular-developers. Here are a few reasons why developers need to Angular-discover Meteor:</p>
<h4>Keeping your skills</h4>
<p>Study of Angular passes in one sitting, and you can be a little ride on an emotional roller coaster. <a href="https://www.bennadel.com/blog/2439-my-experience-with-angularjs---the-super-heroic-javascript-mvw-framework.htm" target="_blank" rel="nofollow noopener">Figure out the article</a> has become quite popular and as Angular-developer, you probably have experienced the beauty of these differences:</p>
<p><img loading="lazy" decoding="async" width="545" height="563" class="alignnone size-medium wp-image-5114" src="https://codemotion.ninja/wp-content/uploads/2016/10/angular-post-3-img-2.png" alt="angular-post-3-img-2" srcset="https://codemotion.us/wp-content/uploads/2016/10/angular-post-3-img-2.png 545w, https://codemotion.us/wp-content/uploads/2016/10/angular-post-3-img-2-290x300.png 290w" sizes="(max-width: 545px) 100vw, 545px" /></p>
<p>Now, you know what Angular.js. When you encounter a Meteor in its pure form, you probably think that &#8220;this is not the best way to get me back again to the handlebars and the jquery&#8221;, or, if you start with Angularjs after Meteor&#8217;a &#8211; the question would look like this: &#8220;I do that, have to learn something new? No way! &#8220;. You will not have to; using Angular-Meteor bundle you save all the skills in the Angular, and in turn, get the opportunity to enjoy all the advantages of Meteor.</p>
<h4>Full stack, as it should be</h4>
<p>MEAN stack &#8211; it is only MongoDB, Express, Angular and Node.js collected together, but this bunch is not seamless. The harsh reality is that you need additional tools to do all this work: a framework for testing, assembly system, the deployment environment, and more. All this emerges the developer who has to somehow communicate, given that the way to address this large set of tasks.</p>
<p>As a result, each MEAN -project looks differently. The file structure of your code is also unique, so other developers will take time to sort out all over when they see your project the first time.</p>
<p>Meteor makes it all much easier. Quick Start packaged system and almost transparent deployment drivers for model projects that any developer can see that where there.</p>
<h4>Honest code isomorphic</h4>
<p>MEAN stack (Mongo, Express, Angualr, Node ) promised to deliver javascript everywhere. Yes, javascript is everywhere, but the code is not always straightforward. It&#8217;s true, at least remember how you interact with data from REST-server.</p>
<ul>
<li>You create a REST point of application</li>
<li>You refer to the point of application using $ http.get ( &#8216;myurl / endpoint&#8217; )</li>
<li>You add the answer to your model: var data = response;</li>
</ul>
<p>Operation Meteor and Angular different. You can actually write code that will run on both the client and the server. You do not need to use third-party solutions such as browseify. It is enough to write once: var data = Data.find ( &#8216;my data&#8217;);</p>
<p><img loading="lazy" decoding="async" width="960" height="720" class="alignnone size-medium wp-image-5116" src="https://codemotion.ninja/wp-content/uploads/2016/10/angular-post-3-img-3.png" alt="angular-post-3-img-3" srcset="https://codemotion.us/wp-content/uploads/2016/10/angular-post-3-img-3.png 960w, https://codemotion.us/wp-content/uploads/2016/10/angular-post-3-img-3-300x225.png 300w, https://codemotion.us/wp-content/uploads/2016/10/angular-post-3-img-3-768x576.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></p>
<h4>Real-Time Applications are easier</h4>
<p>There are many reasons why you love Angular. After all he is doing is called a framework superhero. One of the main reasons is the two-way data binding.</p>
<p>Meteor on his side, and provides you with &#8220;first class&#8221; data binding between the client and the real-time server. This is part <a href="http://docs.meteor.com/#/full/quickstart" target="_blank" rel="nofollow noopener">of the seven principles of the Meteor</a>: database all the data &#8220;on the wire&#8221; invisible compensation.</p>
<p><em>So what Angular or Meteor? Do not choose!</em></p>
<p>Using Angular-Meteor on the client, and the Meteor on both sides, allows the client and server are on the same line with data binding. Everything is synchronized from the database on the server to the user interface and back.</p>
<p>Using the Meteor, you can really use Angular not only when working with REST-services in your application (or even transport socket), but it can speed up the mechanism for creating a modern single-page applications like Gmail, Google without the need for money.</p>
<h4>The story of two communities</h4>
<p>During the 6 years of its existence, Angular largely been accepted and built a large community of contributors and developers that expand its ecosystem. At the same time, Meteor-community is also growing, more and more packets are added to the basic package of the MDG (MEteor Development Group). So why play on the same team when you can win on both sides?</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/5-reasons-angular-makers-favor-using-meteor/">5 reasons for Angular-makers in favor of using Meteor</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></content:encoded>
					
		
		
		
		<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-3-img-2-150x150.png" />
		<media:content url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-3-img-2.png" medium="image">
			<media:title type="html">angular-post-3-img-2</media:title>
			<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-3-img-2-150x150.png" />
		</media:content>
		<media:content url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-3-img-3.png" medium="image">
			<media:title type="html">angular-post-3-img-3</media:title>
			<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/angular-post-3-img-3-150x150.png" />
		</media:content>
	</item>
		<item>
		<title>How to connect to the API backend Angular.js</title>
		<link>https://codemotion.us/connect-api-backend-angular-js/</link>
		
		<dc:creator><![CDATA[Yaroslav Golovach]]></dc:creator>
		<pubDate>Wed, 26 Oct 2016 16:05:31 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[the javascript]]></category>
		<guid isPermaLink="false">https://codemotion.ninja/?p=5094</guid>

					<description><![CDATA[<p>Series &#8220;Developing applications on single-Angular.js&#8221; Why do I need Angular.js and why he Modern tools and framework Angular.js frontend applications Familiarity with controllers and directives Angular.js Writing Services in Angular.js Routing in Angular.js How to connect to the API backend Angular.js In this article we will learn how to connect our application with a simple [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/connect-api-backend-angular-js/">How to connect to the API backend Angular.js</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Series &#8220;Developing applications on single-Angular.js&#8221;</h2>
<ol>
<li><a href="https://codemotion.ninja/blog/development/why-do-i-need-angular-js">Why do I need Angular.js and why he</a></li>
<li><a href="https://codemotion.ninja/blog/development/modern-tools-framework-angular-js-frontend-applications">Modern tools and framework Angular.js frontend applications</a></li>
<li><a href="https://codemotion.ninja/blog/development/familiarity-controllers-directives-angular-js">Familiarity with controllers and directives Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/writing-services-angular-js">Writing Services in Angular.js</a></li>
<li><a href="https://codemotion.ninja/blog/development/routing-angular-js">Routing in Angular.js</a></li>
<li>How to connect to the API backend Angular.js</li>
</ol>
<p>In this article we will learn how to connect our application with a simple API using Restangular library. Restangular &#8211; a popular alternative to the built-in self Angular.js library for working with REST API. On its advantages over the standard library are well described on the project&#8217;s page at github: <a href="https://github.com/mgonto/restangular" target="_blank" rel="nofollow noopener">https://github.com/mgonto/restangular</a>. For example, it supports all the HTTP methods and devoid of various nasty bugs embedded in Angular.js library.</p>
<p>As an API, we will use <a href="https://github.com/mkdev-me/sinatra-api-example" target="_blank" rel="nofollow noopener">a small web application</a>, written in the framework, of Sinatra, which is written in Ruby. You do not need to write ruby code. To run the API on your machine, perform the following steps:</p>
<ol>
<li>Install Ruby if you do not yet have. Online set of guidelines on this subject, including the official website <a href="https://www.ruby-lang.org/en/" target="_blank" rel="nofollow noopener">https://www.ruby-lang.org/en/</a></li>
<li>Download the app <code>git clone https://github.com/mkdev-me/sinatra-api-example</code></li>
<li>Go to the folder with the application and run <code>bundle install</code></li>
<li>Then run <code>rake db:create db:migrate</code></li>
<li>Finally, run the application command <code>ruby app.rb</code></li>
</ol>
<p>Done! Your little backend ready to go at <code>localhost:4567</code>. Now we can update Angular.js application to work with the API.</p>
<p>We have already connected Restangular step setup of our application: you can see it in the list of dependencies in a file <code>bower.json</code>. Moreover, the library is already loaded as a module, pay attention to the line in <code>src/app/index.js</code> :</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">angular.module('ngmkdev', ['restangular', 'ui.router', 'ui.bootstrap'])</pre>
<p>Therefore, we can go directly to the code. First of all, we need to set the base URL, using which Restangular will build more links. To do this, the library has RestangularProvider provider that we can use in the config block in <code>src/app/index.js</code> :</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">// src/app/index.js
angular.module('ngmkdev', ['restangular', 'ui.router'])
  .config(function ($stateProvider, $urlRouterProvider, RestangularProvider) {

    RestangularProvider.setBaseUrl("http://localhost:4567");
    &lt; … &gt;
});</pre>
<p>The main reference for the default will be a link to the server with our API. Now update <code>TransactionsStore</code> so that it uses data from the server. Add two new methods: <code>loadTransactions</code> load all the data from the server, and <code>addTransaction</code> add a new transaction.</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">// src/components/transations_store.serve.js
angular.module('ngmkdev').factory('TransactionsStore', function(Restangular) {
  return {
    transactions: [],
    loadTransactions: function() {
      this.transactions = Restangular.all('transactions').getList().$object;
    },
    addTransaction: function(transaction) {
      var that = this;
      return Restangular.all('transactions').post({transaction: transaction}).then(function() {
        that.transactions.push(transaction);
      })
    },
    sum: function() {
      var sum = 0;
      this.transactions.forEach(function(el) {
        sum += parseFloat(el.amount);
      })
      return sum;
    }
  }
});</pre>
<p>Note the function <code>then()</code>. It is performed only when the completed request to add transaction. This mechanism is called the promises, which is an alternative for the usual jQuery callback mechanism. promise The difference is that we do not need to keep in mind when a callback is executed. Angular.js thus provides a guarantee that if the function A has finished its execution, the function B is executed (and only if the function A really well done).</p>
<p>In this case, we ensure that the array is updated only after the transaction is successfully saved a new transaction to the server. To reduce the number of server requests we will keep in memory all the transactions and update the array manually, instead of each time getting all transaction server.</p>
<p>Most Restangular functions return a promise-objects. For example, <code>getList()</code>, which we use for all transactions. To get yourself a transaction, we can either use <code>then()</code>, a method of <code>$object</code>, which immediately returns us all transactions.</p>
<p>Using the method of <code>all()</code>, we specify with some resource work. Restangular he guesses which links to send and receive data, provided that your application complies with REST API standards. Thus, <code>post()</code> will create a new record, <code>get()</code> will get a record, etc.</p>
<p>Controller code has not undergone major changes:</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">// src/app/main/transactions.controller.js
angular.module('ngmkdev').controller('TransactionsCtrl', function($scope, TransactionsStore) {

  TransactionsStore.loadTransactions();

  this.addTransaction = function() {
    TransactionsStore.addTransaction(this.newTransaction);
    this.resetTransaction();
  }

  this.resetTransaction = function() {
    this.newTransaction = {
      amount: 0.0,
      date: "1993-02-01",
      description: null
    }
  }
  this.transactions = TransactionsStore.transactions;
  this.resetTransaction();
});</pre>
<p>Now all new transactions will be stored in the database and then reload the page, they will not be lost.</p>
<p>You probably created numerous test transactions to see how everything works. Now you have to be on them as something to get rid of. Commit to the changes: <a href="https://github.com/mkdev-me/ng.mkdev/commit/a0629f595db4d49c7e7c956ffcefe1cdb1050be0" target="_blank" rel="nofollow noopener">a0629f</a>.</p>
<p>Homework:</p>
<ul>
<li>Add and implement the delete button transaction.</li>
</ul>
<p>This is the last article on Angular.js course. For 6 issues, we met with all the basic tools of modern frontend development and, following the best practices, a full written application running with the backend via the API. The knowledge gained will serve as an excellent foundation for writing more complex applications Angular.js. Write in the comments what you think about this series and how is your study and application Angular.js.</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/connect-api-backend-angular-js/">How to connect to the API backend Angular.js</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></content:encoded>
					
		
		
		
	</item>
		<item>
		<title>AngularJS for accustomed to jQuery</title>
		<link>https://codemotion.us/angularjs-accustomed-jquery/</link>
		
		<dc:creator><![CDATA[Yaroslav Golovach]]></dc:creator>
		<pubDate>Sat, 08 Oct 2016 08:47:17 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[the javascript]]></category>
		<guid isPermaLink="false">https://codemotion.us/?p=4781</guid>

					<description><![CDATA[<p>Angularjs &#8211; perfect framework for building web applications. He has great documentation provided with examples. In teaching &#8220;test&#8221; applications (such TodoMVC Project ), he is very worthy shows itself from the rest of other frameworks. According to him there are excellent presentations and screencasts. However, if the developer had never encountered frameworks, like Angular, and [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/angularjs-accustomed-jquery/">AngularJS for accustomed to jQuery</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="http://angularjs.org/" target="_blank" rel="nofollow noopener">Angularjs</a> &#8211; perfect framework for building web applications. He has great documentation provided with examples. In teaching &#8220;test&#8221; applications (such <a href="http://todomvc.com/" target="_blank" rel="nofollow noopener">TodoMVC Project</a> ), he is very worthy shows itself from the rest of other frameworks. According to him there are excellent presentations and screencasts.</p>
<p>However, if the developer had never encountered frameworks, like Angular, and used to work mostly like the jQuery library, then it can be difficult to change your way of thinking. At least, so it was with me, and I would like to share some notes on the subject. Perhaps someone it will be useful.</p>
<h4>Not library</h4>
<p>The first thing to understand about Angular: it is a completely different instrument. jQuery &#8211; a library. AngularJS &#8211; this framework. When your code works with the library, he decides when to call this or that function. In the case of framework you implement the event handlers, and have a framework to decide at what point they cause.</p>
<p>This difference is easier to understand if you think about what is happening during the performance. What jQuery does in runtime? Almost nothing. jQuery code is called only in response to something that happened in your code &#8211; when load trigger any of the functions caused by DOM event.</p>
<p>Angular is the download stage turns your DOM tree and angular-code in an application. HTML-page layout with angular-directives and filters it compiled in the template tree corresponding scope (scope) and controllers join them in the right places, internal applications work cycle provides the correct data binding between presentation and model. This is really a working arrangement in full accordance with the principles of MVC, which ensures a very clean separation between the presentation, the controller and the model. If we talk about the overall event loop, rendering pages and data binding, you can assume that it is carried out continuously at all times, causing the code of your controllers only when required.</p>
<p><img loading="lazy" decoding="async" width="625" height="439" class="alignnone size-medium wp-image-4787" src="/wp-content/uploads/2016/10/AngularJS-for-accustomed-to-jQuery-1.png" alt="angularjs-for-accustomed-to-jquery-1" srcset="https://codemotion.us/wp-content/uploads/2016/10/AngularJS-for-accustomed-to-jQuery-1.png 625w, https://codemotion.us/wp-content/uploads/2016/10/AngularJS-for-accustomed-to-jQuery-1-300x211.png 300w" sizes="(max-width: 625px) 100vw, 625px" /></p>
<p>Each model is updated (either through asynchronous AJAX-request or directly through the change of data from the controller) Angular restarts the cycle $ special procedure the digest, which updates the data binding, and retains all the up to date system.</p>
<h4>Declarative approach rather than mandatory</h4>
<p>Unlike some other libraries and frameworks, Angular not HTML as regards the problem, you want to solve (I will not point fingers). Instead, it extends them so naturally that inevitably wondered why he had not previously thought of. It is easier to show than to explain.</p>
<p>Suppose we want to show and hide an element, based on the state of the checkbox. In jQuery, we would do it something like:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;input id="toggleShowHide" type="checkbox"&gt;
&lt;div id=”specialParagraph”&gt;
    This content will disappear and reappear if you click the checkbox above
&lt;/div&gt;</pre>
<p>[divider type=&#8221;linebreak&#8221;]</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">$(function() {
     function toggle() {
        var isChecked = $('#toggleShowHide).is(':checked');
        var specialParagraph = $('#specialParagraph');
        if (isChecked) {
            specialParagraph.show();
        } else {
            specialParagraph.hide();
        }
    }
    $('#toggleShowHide).change(function() {
        toggle();
    });
    toggle();
});</pre>
<p>Note that the javascript code-DOM here perceives in terms of the imperative approach: take this element and its attribute, look at the value, do so-and-so.</p>
<p>Now look at the same thing in terms of Angular:</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;input ng-model="showSpecial" type="checkbox"&gt;
&lt;div ng-show=”showSpecial”&gt;
    This content will disappear and reappear if you click the checkbox above
&lt;/div&gt;</pre>
<p>And yet! Code is not at all, just pure determination declarative style bindings and rules. Here is a demonstration of this code in jsFiddle: <a href="http://jsfiddle.net/Y2M3r/" target="_blank" rel="nofollow noopener">jsfiddle.net/Y2M3r</a></p>
<p>Direct manipulation of the DOM is not simply cease to be binding; we can say even more, their use Angular approach is not recommended. The DOM tree to be fully defined in the templates, data &#8211; in the models and areas of visibility, functionality &#8211; in controllers, any custom transformation &#8211; in their own filters and directives.</p>
<p>This clear division of tasks at first glance looks indigestible, but as the project grows, it will pay off handsomely: the code is easy to maintain, it is easy to divide into modules, is convenient to test and explore.</p>
<h4>Two-way data binding</h4>
<p>The process of tying the value of the DOM data model through the controller and its field of view creates the most that neither is &#8220;binding&#8221; in the full sense of the word. Most likely, you already know this from the documentation and examples, but I just can not say it is not. This is one of the most powerful first impressions of use Angular.</p>
<pre class="prettyprint lang-html" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">&lt;input type="text" ng-model="yourName" placeholder="Your name" /&gt;
&lt;h1&gt;Hello {{yourName}}!&lt;/h1&gt;</pre>
<p>Demonstration: <a href="http://jsfiddle.net/6UnVA/1/" target="_blank" rel="nofollow noopener">jsfiddle.net/6UnVA/1</a></p>
<h4>Implementation depending</h4>
<p>I speak for a few cocky, but Angular implemented the most elegant way to track dependencies in the world.</p>
<p>Assume you have some source of JSON-data, wrapped in a special service $ resource on the side of Angular.</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">DataSource = $resource(url, default_params, method_details)</pre>
<p>(Refer to the documentation for more details)</p>
<p>Any function controller, which requires that data can enable DataSource to your list of options. This is all that is required of it. It&#8217;s a small street magic that never ceases to amaze me every day when working with AngularJS. You need to perform asynchronous HTTP-requests from the controller? Add $ in http settings. We need to write to the console log? Add $ log as an argument to your function.</p>
<p>Inside, at this point, the following occurs: Angular analyzes source code funtsktsii, is a list of arguments and concludes, what services are required to your code.</p>
<h4>Data access</h4>
<p>In addition, Angular that gives you complete freedom of choice in how to organize the data in the model (you can use simple variables, objects and arrays in any combination), it also provides a convenient way to communicate with a REST API on the server. For example, we want to receive and keep a record of users. Here&#8217;s how to access them can be arranged:</p>
<pre class="prettyprint lang-javascript" data-start-line="1" data-visibility="visible" data-highlight="" data-caption="">var User = $resource('/user/:userId', {userId:'@id'});
var user = User.get({userId:123}, function() {
  user.abc = true;
  user.$save();
});</pre>
<p>Angular has a good presets for common sampling operations, delete, retrieve, and modify data. A spetsparametry in the URL gives the ability to customize the access to suit your needs.</p>
<p>Other important points are left out &#8211; it is, for example, form validation, unit testing (not just unit testing, I personally think is even more important than a lot of the article &#8211; approx lane..) And a library angular-ui. Perhaps in future posts.</p>
<p>The post <a rel="nofollow" href="https://codemotion.us/angularjs-accustomed-jquery/">AngularJS for accustomed to jQuery</a> appeared first on <a rel="nofollow" href="https://codemotion.us">Codemotion</a>.</p>
]]></content:encoded>
					
		
		
		
		<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/AngularJS-for-accustomed-to-jQuery-1-150x150.png" />
		<media:content url="https://codemotion.us/wp-content/uploads/2016/10/AngularJS-for-accustomed-to-jQuery-1.png" medium="image">
			<media:title type="html">angularjs-for-accustomed-to-jquery-1</media:title>
			<media:thumbnail url="https://codemotion.us/wp-content/uploads/2016/10/AngularJS-for-accustomed-to-jQuery-1-150x150.png" />
		</media:content>
	</item>
	</channel>
</rss>
