Angular update model from directive
HTML
<script src="http://code.angularjs.org/1.1.0/angular.min.js"></script>
<div ng-app="App">
<div ng-controller="Ctrl" ng-init="init()">
<form name="myForm">
<input type="text" name="field1" ng-model="field1" http-prefix>
</form>
</div>
</div>
JavaScript
var app = angular.module('App', []);
function Ctrl($scope) {
$scope.init = function() {
$scope.field1 = "dummy";
}
}
app.directive('httpPrefix', function() {
return {
restrict: 'E',
scope: {
ngModel: '='
},
link: function(scope, element, attrs, controller) {
element.bind('change', function() {
scope.$apply(function() {
scope.ngModel = 'http://' + scope.ngModel;
});
});
}
};
});