Ng-Style-6

 

In this example of Ng-Style, We have a dropdown with values ng-model="size" that will give the height and width for the image. Whatever selection will be made by the user that will be applied to the image.See the code:

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body ng-app="app"> <div ng-controller="myController"> <div class="row text-center"> <div class="col-md-12"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"> <h4>Image Size</h4> <select class="form-control" ng-model="size" ng-init="size='100'"> <option value="100">100 X 100</option> <option value="200">200 X 200</option> <option value="300">300 X 300</option> <option value="400">400 X 400</option> <option value="500">500 X 500</option> </select> </div> <div class="col-md-4"></div> </div> <div class="row"> <div class="col-md-12"> <img ng-style="style" src="http://learnit.visrosoftware.com/datafiles/enter4.jpg" /> </div> </div> </div> </div> </div> <script> var app = angular.module("app", []); app.controller('myController', ['$scope', function ($scope) { $scope.$watch('size', function (newVal, oldVal) { $scope.style = { 'height': newVal + 'px', 'width': newVal + 'px' }; }); }]); </script> </body> </html>
Output