指令的Javascript代码
angular.directive('uiDatePicker', [function() {
return {
restrict: 'EA',
scope: {
ngModel: '=ngModel',
ngChange: '=ngChange'
},
templateUrl: 'complete/date-picker.tmp.html',
replace: true,
require: 'ngModel',
link: function(scope, elem, attrs, ngModel) {
if(scope.ngModel !== undefined) {
scope.DatePicker = new DatePicker(new Date(scope.ngModel));
} else {
scope.DatePicker = new DatePicker();
}
scope.ngModel = scope.DatePicker.Value;
}
}
}])
控制器的Javascript代码
angular.controller('Main', ['$scope', function($scope) {
$scope.Change = function(value) {
console.log(value);
};
$scope.Value = 1000;
}])
Html代码
<div ng-controller="Main">
<ui-date-picker ng-model="Date" ng-change="Change(Value)"></>
</div>
我的问题:如何改变工作? ngModel仍然有效!