ui-路由器状态控制器在范围内有未定义的 ng-models
ui-router state controller has undefined ng-models in scope
我正在尝试通过注入 ui-router 的控制器来操纵一些输入日期,但我不清楚在这种情况下范围应该如何工作。
附上我的示例场景:
模板html
<div class="date-filter-gallery">
<input type="date" ng-model="date.start">
<input type="date" ng-model="date.end">
</div>
Ui-路由器
.state('stationGallery', {
url: '/station-gallery/{stationId}',
templateUrl: 'src/templates/station-detail.template.html',
controller: 'StationGalleryController as sg',
resolve: {
images: ['$stateParams', 'WeatherStationsService', function ($stateParams, WeatherStationsService) {
return WeatherStationsService.getImagesByStation($stateParams.stationId);
}]
}
});
控制器
StationGalleryController.$inject = ['$scope'];
function StationGalleryController($scope) {
let sg = this;
$scope.date.start = new Date(2017,1,1);
$scope.date.end = new Date(2017,2,1);
}
$scope.date 未定义
我为这个问题道歉,但我是 angular 和 JS 世界的新手。
谢谢
首先实例化$scope.date
对象。例如:
$scope.date = {};
$scope.date.start = new Date(2017,1,1);
$scope.date.end = new Date(2017,2,1);
或者如果您愿意:
$scope.date = {
'start': new Date(2017,1,1),
'end': new Date(2017,2,1)
}
我正在尝试通过注入 ui-router 的控制器来操纵一些输入日期,但我不清楚在这种情况下范围应该如何工作。
附上我的示例场景:
模板html
<div class="date-filter-gallery">
<input type="date" ng-model="date.start">
<input type="date" ng-model="date.end">
</div>
Ui-路由器
.state('stationGallery', {
url: '/station-gallery/{stationId}',
templateUrl: 'src/templates/station-detail.template.html',
controller: 'StationGalleryController as sg',
resolve: {
images: ['$stateParams', 'WeatherStationsService', function ($stateParams, WeatherStationsService) {
return WeatherStationsService.getImagesByStation($stateParams.stationId);
}]
}
});
控制器
StationGalleryController.$inject = ['$scope'];
function StationGalleryController($scope) {
let sg = this;
$scope.date.start = new Date(2017,1,1);
$scope.date.end = new Date(2017,2,1);
}
$scope.date 未定义
我为这个问题道歉,但我是 angular 和 JS 世界的新手。
谢谢
首先实例化$scope.date
对象。例如:
$scope.date = {};
$scope.date.start = new Date(2017,1,1);
$scope.date.end = new Date(2017,2,1);
或者如果您愿意:
$scope.date = {
'start': new Date(2017,1,1),
'end': new Date(2017,2,1)
}