我有一个负责创建网格的指令:
app.directive('gridControl', function () {
return {
restrict: 'E',
scope: {
objectType: "=objecttype",
gridFields: "=gridfields"
},
templateUrl: '/app/templates/modules/gridControl.html',
controller: 'gridControlController'
};
});
控制器如下所示:
standardApp.controller('gridControlController', ["$scope", "$stateParams", "gridControlService",
function gridformController($scope, $stateParams, gridControlService) {
var fields = [];
gridControlService.getGridStructure($stateParams.id).then(function (result) {
fields = result.data.Fields;
});
$scope.mainGridOptions = fields;
}]);
当我想在视图中操作$scope.mainGridOptions时,它是空的!有人能帮我修吗
*注意:我想在then函数之外为$scope.mainGridOptions提供字段数组
原因是gridControlService.getGridStructure($..
关于asynchronous
。使得CCD_ 3从不保持直到CCD_。因此$scope.mainGridOptions = fields;
将在.then(function (result)
之前执行,这意味着fields
只是一个空数组。
我认为$scope.mainGridOptions = fields;
没有必要,你有更好的方法来实现这一点。试试下面的
gridControlService.getGridStructure($stateParams.id).then(function (result)
{
$scope.mainGridOptions = result.data.Fields;
});
// and remove the line $scope.mainGridOptions = fields;