lickmypussyeddievanhalen.ga

Archive for the ‘Uncategorized’ Category

AngularJS Techniques

Friday, September 15th, 2017

Start Working With AngularJS

AngularJS is a Javascript MVC framework created by Google to build properly architectured and maintenable web applications.

AngularJS takes another approach. It attempts to minimize the impedance mismatch between document centric HTML and what an application needs by creating new HTML constructs. AngularJS teaches the browser new syntax through a construct we call directives. Examples include:

Data binding, as in {{}}.
DOM control structures for repeating, showing and hiding DOM fragments.
Support for forms and form validation.
Attaching new behavior to DOM elements, such as DOM event handling.
Grouping of HTML into reusable components.

Why AngularJS?

AngularJS is a MVC framework that defines numerous concepts to properly organize our web application. Our application is defined with modules that can depend from one to the others. It enhances HTML by attaching directives to your pages with new attributes or tags and expressions in order to define very powerful templates directly in your HTML. It also encapsulates the behavior of your application in controllers which are instanciated thanks to dependency injection. Thanks to the use of dependency injection, AngularJS helps you structure and test your Javascript code very easily. Finally, utility code can easily be factorized into services that can be injected in your controllers. Now let’s have a closer look at all those features.

Feature 1: Two Way Data-Binding

Think of your model as the single-source-of-truth for your application. Your model is where you go to to read or update anything in your application.

Data-binding is probably the coolest and most useful feature in AngularJS. It will save you from writing a considerable amount of boilerplate code. A typical web application may contain up to 80% of its code base, dedicated to traversing, manipulating, and listening to the DOM. Data-binding makes this code disappear, so we can focus on our application.

Think of your model as the single-source-of-truth for your application. Your model is where you go to to read or update anything in your application. The data-binding directives provide a projection of your model to the application view. This projection is seamless, and occurs without any effort from you.

Traditionally, when the model changes, the developer is responsible for manually manipulating the DOM elements and attributes to reflect these changes. This is a two-way street. In one direction, the model changes drive change in DOM elements. In the other, DOM element changes necessitate changes in the model. This is further complicated by user interaction, since the developer is then responsible for interpreting the interactions, merging them into a model, and updating the view. This is a very manual and cumbersome process, which becomes difficult to control, as an application grows in size and complexity.

There must be a better way! AngularJS’ two-way data-binding handles the synchronization between the DOM and the model, and vice versa.

Here is a simple example, which demonstrates how to bind an input value to an

element.

Name:

Enter a name here

Hello, {{yourName}}!

This is extremely simple to set up, and almost magical…

Feature 2: Templates

It’s important to realize that at no point does AngularJS manipulate the template as strings. It’s all the browser DOM.

In AngularJS, a template is just plain-old-HTML. The HTML vocabulary is extended, to contain instructions on how the model should be projected into the view.

The HTML templates are parsed by the browser into the DOM. The DOM then becomes the input to the AngularJS compiler. AngularJS traverses the DOM template for rendering instructions, which are called directives. Collectively, the directives are responsible for setting up the data-binding for your application view.

It is important to realize that at no point does AngularJS manipulate the template as strings. The input to AngularJS is browser DOM and not an HTML string. The data-bindings are DOM transformations, not string concatenations or inner HTML changes. Using the DOM as the input, rather than strings, is the biggest differentiation AngularJS has from its sibling frameworks. Using the DOM is what allows you to extend the directive vocabulary and build your own directives, or even abstract them into reusable components!

One of the greatest advantages to this approach is that it creates a tight workflow between designers and developers. Designers can mark up their HTML as they normally would, and then developers take the baton and hook in functionality, via bindings with very little effort.

Here is an example where I am using the ng-repeat directive to loop over the images array and populate what is essentially an img template.

function AlbumCtrl($scope) {
scope.images = [
{"thumbnail":"img/image_01.png", "description":"Image 01 description"},
{"thumbnail":"img/image_02.png", "description":"Image 02 description"},
{"thumbnail":"img/image_03.png", "description":"Image 03 description"},
{"thumbnail":"img/image_04.png", "description":"Image 04 description"},
{"thumbnail":"img/image_05.png", "description":"Image 05 description"}
];
}

{{image.description}}

It is also worth mentioning, as a side note, that AngularJS does not force you to learn a new syntax or extract your templates from your application.

Feature 3: MVC

AngularJS incorporates the basic principles behind the original MVC software design pattern into how it builds client-side web applications.

The MVC or Model-View-Controller pattern means a lot of different things to different people. AngularJS does not implement MVC in the traditional sense, but rather something closer to MVVM (Model-View-ViewModel).

The Model

The model is simply the data in the application. The model is just plain old JavaScript objects. There is no need to inherit from framework classes, wrap it in proxy objects, or use special getter/setter methods to access it. The fact that we are dealing with vanilla JavaScript is a really nice feature, which cuts down on the application boilerplate.

The ViewModel
A viewmodel is an object that provides specific data and methods to maintain specific views.

The viewmodel is the $scope object that lives within the AngularJS application. $scope is just a simple JavaScript object with a small API designed to detect and broadcast changes to its state.

The Controller
The controller is responsible for setting initial state and augmenting $scope with methods to control behavior. It is worth noting that the controller does not store state and does not interact with remote services.

The View
The view is the HTML that exists after AngularJS has parsed and compiled the HTML to include rendered markup and bindings.

This division creates a solid foundation to architect your application. The $scope has a reference to the data, the controller defines behavior, and the view handles the layout and handing off interaction to the controller to respond accordingly.

Feature 4: Dependency Injection

AngularJS has a built-in dependency injection subsystem that helps the developer by making the application easier to develop, understand, and test.

Dependency Injection (DI) allows you to ask for your dependencies, rather than having to go look for them or make them yourself. Think of it as a way of saying “Hey I need X’, and the DI is responsible for creating and providing it for you.

To gain access to core AngularJS services, it is simply a matter of adding that service as a parameter; AngularJS will detect that you need that service and provide an instance for you.

function EditCtrl($scope, $location, $routeParams) {
// Something clever here…
}
You are also able to define your own custom services and make those available for injection as well.

angular.
module(‘MyServiceModule’, []).
factory(‘notify’, ['$window', function (win) {
return function (msg) {
win.alert(msg);
};
}]);

function myController(scope, notifyService) {
scope.callNotify = function (msg) {
notifyService(msg);
};
}

myController.$inject = ['$scope', 'notify'];

Feature 5: Directives

Directives are my personal favorite feature of AngularJS. Have you ever wished that your browser would do new tricks for you? Well, now it can! This is one of my favorite parts of AngularJS. It is also probably the most challenging aspect of AngularJS.

Directives can be used to create custom HTML tags that serve as new, custom widgets. They can also be used to “decorate” elements with behavior and manipulate DOM attributes in interesting ways.

Here is a simple example of a directive that listens for an event and updates its $scope, accordingly.

myModule.directive(‘myComponent’, function(mySharedService) {
return {
restrict: ‘E’,
controller: function($scope, $attrs, mySharedService) {
$scope.$on(‘handleBroadcast’, function() {
$scope.message = ‘Directive: ‘ + mySharedService.message;
});
},
replace: true,
template: ‘

};
});

Then, you can use this custom directive, like so.

Creating your application as a composition of discrete components makes it incredibly easy to add, update or delete functionality as needed.

we will discuss here about how to set up AngularJS library to be used in web application development. We will also briefly study the directory structure and its contents.

When you open the link https://angularjs.org/, you will see there are two options to download AngularJS library -

AngularJS Download
View on GitHub – Click on this button to go to GitHub and get all of the latest scripts.

Download AngularJS 1 – Or click on this button, a screen as below would be seen -

AngularJS Download
This screen gives various options of using Angular JS as follows -

Downloading and hosting files locally

There are two different options legacy and latest. The names itself are self descriptive. legacy has version less than 1.2.x and latest has 1.5.x version.

We can also go with the minified, uncompressed or zipped version.

CDN access – You also have access to a CDN. The CDN will give you access around the world to regional data centers that in this case, Google host. This means using CDN moves the responsibility of hosting files from your own servers to a series of external ones. This also offers an advantage that if the visitor to your webpage has already downloaded a copy of AngularJS from the same CDN, it won’t have to be re-downloaded.

Try the new angularJS 2 – Click on this button to download Angular JS beta 2 version.This version is very fast, mobile supported and flexible compare to legacy and

latest of AngularJS 1

We are using the CDN versions of the library throughout this tutorial.

Example
Now let us write a simple example using AngularJS library. Let us create an HTML file myfirstexample.HTML as below -

Welcome {{helloTo.title}} to the world of Tutorialspoint!

Following sections describe the above code in detail -

Include AngularJS

We have included the AngularJS JavaScript file in the HTML page so we can use AngularJS -

If you want to update into latest version of Angular JS, use the following script source or else Check the latest version of AngularJS on their official website. Point to AngularJS app Next we tell what part of the HTML contains the AngularJS app. This done by adding the ng-app attribute to the root HTML element of the AngularJS app. You can either add it to HTML element or body element as shown below -

View
The view is this part -

Welcome {{helloTo.title}} to the world of Tutorialspoint!

ng-controller tells AngularJS what controller to use with this view. helloTo.title tells AngularJS to write the “model” value named helloTo.title to the HTML at this
location.

Controller
The controller part is -

This code registers a controller function named HelloController in the angular module named myapp. We will study more about modules and controllers in their respective chapters. The controller function is registered in angular via the angular.module(… ).controller(… ) function call.

The $scope parameter passed to the controller function is the model. The controller function adds a helloTo JavaScript object, and in that object it adds a title field.

Execution
Save the above code as myfirstexample.HTML and open it in any browser. You will see an output as below -

Welcome AngularJS to the world of Tutorialspoint!
When the page is loaded in the browser, following things happen -

HTML document is loaded into the browser, and evaluated by the browser. AngularJS JavaScript file is loaded, the angular global object is created. Next, JavaScript which registers controller functions is executed.

Next AngularJS scans through the HTML to look for AngularJS apps and views. Once view is located, it connects that view to the corresponding controller function.

Next, AngularJS executes the controller functions. It then renders the views with data from the model populated by the controller. The page is now ready.

Getting Your Online Business Started

Friday, September 15th, 2017

Any business starts with an idea. Turning the idea into a profitable business takes time and dedication. It doesn’t happen overnight. There are a few fairly easy ways to turn your business into a profitable website.

Online businesses are part of the internet. The internet is full of people searching for things from all over the world. This is one reason to have a website. You will be able to reach many more people than a local business. In order to get your website started you need to have a domain name. This is the name of your business online. You can search through places like GoDaddy to find available website or domain names. Usually a domain name will cost about 7.99 and up for a year. You will need to pay this cost each year to keep your website or business name online. You want to be sure that your domain name fits with the type of business you have online. If you sell clothes you don’t want to use a domain name that goes with selling pet food. You also have to make sure this is a unique name that is only used by your business.

So you’ve got your domain name, but that’s not all. You have to choose a web host provider. In order for your website to function right you need a good company to host your website on their server. Some good web host providers include BlueHost, Startlogic and Resellers Web host. Make sure it is a reliable company with good reviews. You don’t want to have your website with error messages or saying this website is under construction. If you can’t see your website chances are other people can’t. If you wish to avoid this choice you may wish to use a company like Wix which will do these things for you for a monthly fee.

Now you need to list your business and product information. Even if your business is an Ecommerce website it is still important to have good content. In other words, describe your products well. Also make sure you have good pictures of your products. A picture says a thousand words. Even if you go through a company like Wix you are responsible for managing the pictures, products and information on your website. If your website is more of a blog or information website you may wish to go through WordPress which is free for blog type websites.

In order to be a profitable business you need to make money. You may need to use money to advertise but make sure you are reaching a targeted audience. You want people to come to your website who are looking to buy from you. There are several ways to advertise your website for free. Social media like Twitter and LinkedIn are great ways to do this.

In order to get the right people to your website, be sure to do some good SEO or Search Engine Optimization. WordPress Ecommerce is a great program to use in order to make this step easier. There is a learning curb but if you check forums and do some research you will learn how to do this step yourself. You may wish to hire a programmer if it is too complicated. Be sure to use good keywords and keyword phrases. If you are selling perfume, you don’t want to use keywords like pets, food or words that have nothing to do with your products.

These steps may seem a bit overwhelming, but study each one at your own pace. Stay focused and keep doing what you know to do. It takes time to get your website to be a productive online business but it is very possible. Keep learning and stay encouraged.