AngularJS Example:

by HaJIuBauKa

HTML

<form ng-controller="MyCtrl" ng-app="app">
  <div isolate-num>
      <input type="number" ng-model="num" min="1" max="5" />
      <input type="range"  ng-model="num" min="1" max="5" />
  </div>
  <div isolate-num>
      <input type="number" ng-model="num" min="1" max="5" />
      <input type="range"  ng-model="num" min="1" max="5" />
  </div>
</form>

JavaScript

var app = angular.module("app", []);

app.controller('MyCtrl', ['$scope', function($scope){
    
}]);

app.directive('isolateNum', [function(){
    return {
        scope: true,
        restrict: "A",
        link: function($scope, el, attrs) {
            $scope.num=1;
            $scope.$watch('num', function(num) {
                $scope.num = parseInt(num);
            });
        }
    }
}])