Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app="app" ng-controller="AppCtrl">
  <form name="form" class="container">
    <label> Custom control</label>
    <my-control name="field" ng-model="text"></my-control>
    <div><b>Model value:</b> {{text}}</div>
  </form>
  <script type="text/ng-template" id="myControl.tpl">
    <input type="text" ng-model="value" class="form-control" ng-pattern="'^(?!ng-*)'" minlength="3">
    <div><b>Errors:</b> {{innerModel.$error}}</div>
  </script>
</body>
</html>
 
angular.module('app', []).controller('AppCtrl', function($scope) {
  $scope.text = "not-ng";
}).directive('myControl', function() {
  return {
    restrict: 'E',
    require: 'ngModel',
    templateUrl: 'myControl.tpl',
    scope: {},
    link: function(scope, elm, attrs, ngModel) {
      scope.innerModel = elm.find('input').data('$ngModelController');
      ngModel.$render = function() {
        scope.value = ngModel.$viewValue;
      };
      scope.$watch('value', function(value) {
        ngModel.$setViewValue(value);
      });
    }
  };
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers