Home
Run >
<!DOCTYPE html> <html> <head> <!-- www.techstrikers.com --> <title>AngularJS $scope.identity() Example</title> <script SRC="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script> <script> var app = angular.module('IdentityInitialization', []) app.controller('IdentityController', ['$scope', function($scope) { $scope.Url = "www.techstrikers.com"; $scope.getURL1 = function(url) { return url; }; $scope.getURL2 = function(url) { return url; }; $scope.getResult = function(fn, val) { if (fn) { return fn(val); } else { return angular.identity(val); } }; $scope.functionOne = function(fn, val) { $scope.result = $scope.getResult($scope.getURL1,$scope.Url); }; $scope.functionTwo = function(fn, val) { $scope.result = $scope.getResult($scope.getURL2,$scope.Url); }; }]); </script> </head> <body style="background-color:#DDE4E9;" ng-app="IdentityInitialization"> <fieldset style="background-color:#DDE4E9;"> <legend>AngulerJS $scope.identity() Example</legend> <div ng-controller="IdentityController"> <p style="font-family:Arial;color:red;background:steelblue;padding:3px;width:350px;">{{result}}</p> <input ng-model="Url"> <button ng-click="functionOne()">functionOne</button> <button ng-click="functionTwo()">functionTwo</button> </fieldset> </body> </html>