Skip to main content

Posts

Showing posts from November, 2014

$watch vs $on in angularjs

$On() The $on is used to listen to each events. $on also work to push a function into a stack and returns to another function and clean the original functions from that stack. $watch() The angularjs create watch internally. The watch means that angularjs watches the changes in the variable on the $scope object. The watches are created using the $scope.$watch() method. The $scope.watch() method creates a watch of some variables.  When you register a watch you need to pass two functions 1. One is value function 2. and other is listener function for example $scope.$watch(function() {},function() {});

$http.get $http.post and $http.put in angularjs

The $http service is provide the communication over the browsers using to XMLHttpRequest object or JSONP object. The types of $http service     $http.get()     $http.head()     $http.post()     $http.put()     $http.delete()     $http.jsonp()     $http.patch() The General usage of $http service.     $http.get( '/putUrl' ).success(callback);     $http.post( '/putUrl' , data).success(callback);     $http.put( '/putUrl' , data).success(callback); //The $http.post() and $http.put() methods accept any object value or a string value in the place of data. The $http service is an asynchronous call. The $http() service returns a $promise that we can add handlers .then() method for example:  $http({         url: 'licalhost://8080/api/updateEmployee/ids' ,         method: "POST" ,         data: { 'id' : 1 }     })     .then( function (response) {         // if success then todo here

Get select value from kendo ui comboBox

In this post, is going to share the how to bond the kendo ui Combo Box &  how to get the value and text using this.value() , this.text() and we can use as per need. This combo box wok with filter. If you want to filter the  drop-down  the it possible. The Razor view code sample : < div class ="col-lg-12">       < input type ="text" id ="txt_filterCustomer"/> </ div > The JavaScript code sample : < script type ="text/javascript">     var _empId = mySession().ID;    //This is a Id.     $( function () {         $( "#txt_filterCustomer" ). kendoComboBox ({             placeholder: "-- Select Employee --" ,             dataTextField: "EmpName" ,             dataValueField: "EmpID" ,             filter: "contains" ,             autoBind: false ,             minLength: 1,             dataSource: {                 transport:

set default value in dropdown list in angularjs

This is interesting question, how to set default value in option or  drop-down   list using angular.  We can achieve the angular directive with two way binding ng-model and ng-option also. In the below example code, bind the collection on ng-option and countryId from country collection on ng-model . Go to live demo link  http://embed.plnkr.co/Wlw62X/preview Using the we can bind the collection in option or drop-down list. If you want to set the default value, that time need to add default countryId within the controller $scope. The code look like [ $scope.register.countryId = "1"; ]   // This is the default countryId . The example code as given below. < !DOCTYPE html > < html > < head >     < script src ="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></ script >     < script >         angular.module( "myapp" , [])           .controller( "

How to call AJAX Request in AngularJs?

I am going to share the code sample for the ways of calling AJAX Request using $http.get(), $http.post(),  $http.put(),  $http.post(),  $http. delete() or  $http.head()  methods in angularjs. Table of Content   $http  service   $http function   $http as a function   The config parameter   The success() And error() functions in angularjs Ajax The angularjs  AJAX R equest manage in different types. The types re given below. AJAX call over the $http services. REST API Call over the $http services. JSON Call over the $http services. The $http services is a way of sending AJAX request on the web servers.  The $http and $scope both are managed by the controller function. The functions over the $http service that is called $http function. The function list as given below. $http.get(url, config); $http.post(url, data, config); $http.put(url, data, config); $http.delete(url, config); $http.head(url, config); Here we can also used the $http services as fun

$scope vs scope in angularjs

This is interesting question and little bit confusion about $scope and scope and how to differentiate to in controller and directive both case in Angularjs. In the case of controller, When you are using $scope in controller.  The injection inject scope based on matching valuable name ( $scope ). In case when we using scope as name its not work. The code look like. {{         app.controller( "MyController" , [ '$scope' , '$http' , function (i, j) {               console.log( "$scope : " + i);               console.log( "scope : " + j);           }         ]); }} In the case of directive, Injection work position based. So you take your name anything like i, j etc. Just you can say look like scope, element,  attar and controller. That means the 1st element is always scope object. It must be. The code look like. {{         app.directive( "MyDirective" , function () {