Wednesday, 29 November 2017

Basic Game : 4 x 4 Matrix puzzle by using Javascript and Jquery


In this article I had planned with a number puzzle game of 4 x 4 matrix. Here I'm working by using javascript and Jquery. In my upcoming articles I'll go with angular too definitely.
All the code I did is just based on my written algorithm or  views. We can even reduce the code that what I done with, I welcome all the code reduce inputs in comment section.
you can test the code by copying and pasting in the below link of try it editor.

Saturday, 25 November 2017

Angular Basic Interview Questions Set-3

<< Previous Questions with Answers

21)what is $on ?
$on function in angular is used to listen the event that has been triggered.It listens the events that are triggered by using $broadcast and $emit functions.$on is one of the function of $scope which can be initialized like $scope.$on
syntax :
app.controller('ctrlname', function($scope){
  $scope.$on('emitorbroadcast', function(){    
   //our code
  })
});

22)How can you create your own directive ?
By using custom directives we can create our own directives with certain behavior adding to it. That created directive can be used as an markup element in our view.
syntax:
myApp.directive(‘ourdirective’, function() {
    return {
        restrict: ‘E’,
        template: ‘<h1>I made a directive!</h1>’
    };
});
Using in view :
<ourdirective> </ourdirective>

23)What is link ?
While bootstraping the angular, the compiler cant get perform actions over the scope members. To get start working over them it should pass over the link phase where the scope values get initialised, ofcourse we get the compile phase before getting to this step but the instance of our directives template will gets generated at link itself.If we define the link key with its function as value then it executes as like the post-link by default.

24)What is compile ?
In the process of bootstrap, the parser gets hit to the $compile function where this function grabs all the templates related to the directives. At this phase we cant play with the scope for the templates as the instance will not be created.The compile phase will gets compiled only once for the template and the impact of its logic will apply to all created instances later.The return type of the compile phase will be as pre and post functions.

25)What is the order of execution between pre, post and compile ?
  • Initially, the compile phase will gets executed which returs pre/post functions.
  • After compile phase getting executed, the pre-link will execute.
  • As soon as the pre-link executed goes to the post functions execution flows from bottom-top trace over the custom directive concern template.

26)What is pre ?
In pre-link function we won't get access towards the child elements which we careated by the directives.In some cases we may have to use the parent and child elements as custom directives. At that situation for some of the child elements(created via directive) scope values can make enable at the pre-link function itself as they execute firstly then moves to post while parsing. 

27)What is post ?
Post function in the custom directives is mostly preferrred place to write any kind of logic over the template as the parent & child, both elements with its template related instance and scope will be available.
For more details related to the pre and post find in the followed link :

28)What is restrict ?
Restrict is used as one of the key in the custom directives. By using this key we can make or set the behavior of our directive which we are creating. The restrict can be of four modes as follows :

E - Restrict with value as "E" will behaves as an element in our view.
A - Restrict with values as "A" will behaves as an attribute for an element in our view.
C - Restrict with values as "C" will acts as a class for an element.
M - Restrict with values as "M" will acts as a comment.

29)Does angular allows nested controllers using ?
Yes, we can also use the nested controllers based on the requirement.

30)Can we go for $watch in the compile phase ?
No, as compile is the initial phase over the directive, It just creates the template for the directive while parsing over the DOM. So, we can't access the scope members. We can play over $watch in the post function.

Wednesday, 22 November 2017

Custom Directives in Angular JS Part-2

    If you are new to custom directives creation please have a look of part-1 of this series in the followed link Custom Directives Part-1
In this part-2 lets discuss related to the concepts of compile & link keys using in custom directives.
Compile key in Custom Directive :
In general,for every directive there will be a compilation phase. This phase comes whenever the angular parser faces the directive for the element while parsing. pro grammatically this

Monday, 20 November 2017

About Me

I'm Sreekanth, currently working as a software engineer, developing web applications on .net platform.I was very much passionate towards learning and sharing new things related to technologies.I believe that technical knowledge will gets improved a lot while learning and sharing the knowledge. I always likes to be in a positive manner whenever I face my flaws while working.All of sudden I  started focusing on angular JS which was a wonderful framework. I thought to share my known things on this(Angular JS) technology which might be helpful to other developers too. As a
developer I always likes to be within the following loop:

                                                               while(learner)
                                                               {
                                                                        //Learn the unknown things.
                                                                        //Share the things you know.
                                                                        //Accept the faults/flaws if any.
                                                                        //Correct yourself if you are mistake.
                                                                }

I strongly believe that until we are in the above loop the graph of our knowledge will be in raising state.


Thank you.

Friday, 17 November 2017

Custom Directives in angular JS - Part : 1


Introduction :
Directives in angular JS is the key concept, which can provide an additional behavior/feature to the HTML element. The main or major directives which usually a beginner even might be knowing is ng-app or else ng-controller as those are the base things to bootstrap and consume the angular things.
Here comes a point, is it possible to create our own directives with a certain behavior adding based on our requirement. Yes, angular enabled the feature to create our own directives.
You might be wondering, as like why should I create a custom directive, as we are having lot of properties or features existing. Assume we may get an element with certain behavior which we got need to have an in lot of places of our project, In that scenario instead of writing its logic and accessing, just we can create our own directive and use it as an HTML element or an attribute or even as a class wherever we required.
Remember a thing that our custom directive can act as a directive or css classes or element.
Syntax of custom directive :

Thursday, 9 November 2017

Angular Basic Interview Questions Set-2


11)What is a module ?
Module in angular JS behaves as a case for the different parts like services, values, filters e.t.c. which were the concepts in angular JS. In  HTML wherever we declare the ng-app, making that as start and end with concern closing tag that whole part comes under the module from the view part.
module syntax : var myapp = angular.module('myapp', []);
Using in view :
<div ng-app='myapp'>
//...
</div> 

12)What are controllers ?
Controller in angular JS is nothing but a constructor function.

Monday, 6 November 2017

Scope processing and scope inheritance


         Scope in angular JS is an object. Scope is used to set as a mediator between the controller and view. The process of the scope will be as like below pattern :
1)      Creation of scope.
2)      Creation of controller instance.
3)      Execution of the controller function.
4)      View setting up with model values.
5)      Destroy the $scope
1)Creation of scope :
Whenever the angular parser reads the ng-controller directive in the view, at that moment initially it


Friday, 3 November 2017

using $emit and $on in angular JS


Angular provided us the event based data transfer from one control to another by using $broadcast and $emit. To know about $broadcast usage click the link: using $broadcast and $on  .
In this section lets look over the usage of $emit and $on functions.$emit and $on are the functions of the $scope object.
$emit is the one that which propagates the event to upward direction, by using this function we can pass the data to the called one.

Thursday, 2 November 2017

Using $broadcast and $on in angular JS


         Situations may raise that which we needs to call the one controllers function in another controller. Even though we are having lot of other options angular provided us event based call from one controller to another controller it can be achieved by using $broadcast and $emit functions.
As of now in this article I’ll discuss the usage of $broadcast .
$broadcast is a method that which is used to produce or share the method information to downwards. As I said downwards, means the start comes from the controller where we used.


Wednesday, 1 November 2017

Using $scope.$watch() in angular JS


$watch() in angular JS is the function of $scope object. Watchers in angular JS are used to observe the state of the variable which means whenever the $scope variable or model variable has been changed the watcher will listen over it and updates the variable value.Angular, also gave us option to make use of watcher mannually by using this $watch programmatically even.In this section I’m going through, how to use the $watcher function.
To know more about watchers theory follow my link : Watchers in angular JS .

Syntax of $scope.$watch:
$scope.$watch('modelvalue',
              function (newval,oldval) {   } 
              );

In the above syntax If we observe, the $watch() function accepts two arguments.