Monday, December 28, 2015

Services vs Factories in angularjs

Hi Viewers,

Both are will be return object literal.

Services

Services is a constructor function

E.g :

app.service('myservice', function(name) {
  this.sayhello = function(name) {
    return "hi" + name + "!";
  }
});

app.controller('myController', function(myservice) {
$scope.name = "Nutty";
   myservice.sayhello($scope.name);
});

Factories

Factory function is really just a function that gets called, which is why we have to return an object explicitly.

E.g :

app.factory('myfactory', function(name) {

return {
   sayhello : function(name) {
      return "Hi " + name + "!";
    }
}
});

Thanks
Nutty

How to get the parent controller value using in angularjs

Hi viewers,

Parent Controller

$username ="xxxxxxxxxxxxx";

$rootScope.$broadcast("parentValue", $username);

Child Controller 

$scope.childValue = $scope.$on('parentValue');

console.log($scope.childValue);

Thursday, December 24, 2015

Directives in angularjs

Two types of Directives used Angularjs
1) InBuild Directive
2) Custom Directives

Inbuilt Means : 
  E.g : ng-app, ng-click , ng-class

Custom Directives : 
  E.g : Data-ng-sample

 We have achieve four types
    A) Attribute,
    B) Element,
    C) Classes,
    D) Comment