DirectivaTest2
by Bobris
HTML
<div ng:app="hifiDate">
<div ng-controller="Ctrl2">
<div ng-repeat="res in resources"><ng-file-chooser ng-model="res.name"/></div>
<ng-file-chooser ng-model="resources[0].name"></ng-file-chooser>
<pre>{{resources}}</pre>
</div>
</div>
CSS
</style><script src="http://docs-next.angularjs.org/angular-1.0.0rc2.min.js"></script>
<style>
JavaScript
function Ctrl2($scope) {
$scope.resources = [{name: 'res1'}, {name:'res2'}];
}
hifidate = angular.module('hifiDate', []);
hifidate.directive("ngFileChooser", function () {
var directiveDefinitionObject = {
restrict: 'E',
replace: true,
require: 'ngModel',
scope: true,
template: '<div><input type="text" ng-model="model"/><input type="submit" ng-click="choose()" value=" ... "/></div>',
link: function (scope, element, attr, conts) {
scope.choose = function () {
scope.model = "demo selected";
};
conts.$render = function () {
scope.model = conts.$viewValue;
}
scope.$watch(function (scope) { return scope.model; }, function (value) {
conts.$setViewValue(value);
});
}
};
return directiveDefinitionObject;
});