问题描述
根据文档写了一个demo,放到生产环境测试发现获取不到model值,有同样使用该插件的同学碰到类似问题吗,求教。
github:https://github.com/fragaria/a...
HTML:
<p ng-controller='AppCtrl'> <input date-range-picker type='text' ng-model='date' options='{timePicker: true,timePickerIncrement: true,timePicker24Hour: true,timePickerSeconds: true,locale: { applyLabel : ’确定’, cancelLabel : ’取消’, fromLabel : ’起始时间’, toLabel : ’结束时间’, customRangeLabel : ’自定义’, daysOfWeek : [ ’日’, ’一’, ’二’, ’三’, ’四’, ’五’, ’六’ ], monthNames : [ ’一月’, ’二月’, ’三月’, ’四月’, ’五月’, ’六月’, ’七月’, ’八月’, ’九月’, ’十月’, ’十一月’, ’十二月’ ], format: ’YYYY-MM-DD HH:mm:ss’} }'/> <a href='javascript:;' ng-click='getDate()'>save</a></p>
JS:
var app = angular.module(’test’,[’daterangepicker’]);app.config(function($interpolateProvider,$httpProvider, $controllerProvider, $compileProvider, $filterProvider, $provide){ });app.controller(’AppCtrl’,function($scope,$http){ $scope.getDate = function(){console.log($scope.date); } $scope.$watch(’date’, function(newDate) {console.log(’New date set: ’, newDate); }, false);});angular.bootstrap(document,[’test’]);
问题解答
回答1:这个可能是js由js中对象是引用,值是复制的机制造成的
试下把绑定的变量挂载在一个对象上
像github里面的代码一样
exampleApp.controller(’TestCtrl’, function ($scope) { $scope.datePicker.date = {startDate: null, endDate: null};}