Monday, May 21, 2018

What is scope in Angular Js

Angular Js Scope

The scope is the binding part between the HTML (view) and the JavaScript (controller).
The scope is an object with the available properties and methods.
The scope is available for both the view and the controller.


How to Use Scope ?


<div ng-app="myApp" ng-controller="myCtrl">

<h1>{{carname}}</h1>

</div>

<script>
var app = angular.module('myApp'[]);

app.controller('myCtrl'function($scope) {
    $scope.carname "Volvo";
});
</script>


When adding properties to the $scope object in the controller, the view (HTML) gets access to these properties.
In the view, you do not use the prefix $scope, you just refer to a propertyname, like {{carname}}.


Understanding the Scope

If we consider an AngularJS application to consist of:
  • View, which is the HTML.
  • Model, which is the data available for the current view.
  • Controller, which is the JavaScript function that makes/changes/removes/controls the data.
Then the scope is the Model.
The scope is a JavaScript object with properties and methods, which are available for both the view and the controller.


Example

If you make changes in the view, the model and the controller will be updated:
<div ng-app="myApp" ng-controller="myCtrl">

<input ng-model="name">

<h1>My name is {{name}}</h1>

</div>

<script>
var app = angular.module('myApp'[]);

app.controller('myCtrl'function($scope) {
    $scope.name "John Doe";
});
</script>




                                                  Source: https://www.w3schools.com/

Thursday, August 31, 2017

What is Angular Js

AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology.
AngularJS is what HTML would have been, had it been designed for applications. HTML is a great declarative language for static documents. It does not contain much in the way of creating applications, and as a result building web applications is an exercise in what do I have to do to trick the browser into doing what I want?

Tuesday, February 14, 2017

Validate Emailid Using Regex Javascript

Validate email id with regex expression.

if(email!='') {
             var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
             if( !emailReg.test( email ) ) {
                    alert('Please enter valid email');
                    $("#email").focus();
                    return false;
                   
               }
            }

Thursday, October 13, 2016

Create date format Day,month year wise

 Create a date format using php like:
Today at 05:41pm
22 Sep, at 04:42pm



function create_date_format($postDate){
        $formatted_date='';
        $timestamp    =    strtotime($postDate);
        $date         =     date('Y-m-d', $timestamp);
        $dayname     =     date('D', $timestamp);
        $now = time(); // or your date as well
        $datediff = $now - $timestamp;
        $no_of_days = floor($datediff / (60 * 60 * 24));
        $currentYear = date('Y');
        $postYear     = date("Y",$timestamp);
       
        //echo date('Y-m-d',strtotime("-7 days"));
        if($date == date('Y-m-d')){
            return $formatted_date = "Today "." at ".date('h:ia', $timestamp);
        } elseif($date == date('Y-m-d',strtotime("-1 days"))){
            return $formatted_date = "Yesterday at ".date('h:ia', $timestamp);
        } else {           
            if($no_of_days<7){
                if($dayname=="Mon"){
                    $formatted_date = "Monday at ".date('h:ia', $timestamp);
                }elseif($dayname=="Tue"){
                    $formatted_date = "Tuesday at ".date('h:ia', $timestamp);
                }elseif($dayname=="Wed"){
                    $formatted_date = "Wednesday at ".date('h:ia', $timestamp);
                }elseif($dayname=="Thu"){
                    $formatted_date = "Thursday at ".date('h:ia', $timestamp);
                }elseif($dayname=="Fri"){
                    $formatted_date = "Friday at ".date('h:ia', $timestamp);
                }elseif($dayname=="Sat"){
                    $formatted_date = "Saturday at ".date('h:ia', $timestamp);
                }elseif($dayname=="Sun"){
                    $formatted_date = "Sunday at ".date('h:ia', $timestamp);
                }
            }else{
                if($currentYear>$postYear){
                    $formatted_date = date('d M Y,', $timestamp)." at ".date('h:ia', $timestamp);
                }else {
                    $formatted_date = date('d M,', $timestamp)." at ".date('h:ia', $timestamp);
                }
            }
        }
        return $formatted_date;

}

Friday, September 30, 2016

How can i disabled esc key from JQuery Modal box?

By using this :
         $("#join_login").modal({backdrop: 'static',keyboard: false});

Saturday, August 10, 2013

How can i show a div using jquery

<script type="text/javascript">
$(function(){
$('.mycheck').change(function () {
    if ($(this).attr("checked"))
    {
        $('.mychkdiv').fadeIn(100);
        return;
    }
   $('.mychkdiv').fadeOut();
});

});
</script>
<style>
.mychkdiv { width:400px; padding:20px; background-color:yellow; display:none;}
</style>
 </head>

 <body>
hello this is checkbox  <input type="checkbox" class="mycheck" name="chk"/>
<div class="mychkdiv" style="display:none">sfdadasds</div>

Thursday, October 21, 2010

What is scope in Angular Js

Angular Js Scope The scope is the binding part between the HTML (view) and the JavaScript (controller). The scope is an object with th...