使用自定义指令更改

时间:2014-10-19 16:47:04

标签: javascript angularjs angularjs-directive

指令的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仍然有效!

0 个答案:

没有答案