我的代码是
$scope.loadQuestions = function() {
$scope.questionCount = 0;
$scope.questionTable = new NgTableParams({
count: []
}, {
total: 19387,
getData: function($defer, params) {
$scope.filter.sort = params.orderBy();
$scope.filter.page = params.page();
return $http.get("/api/questions", {
params: $scope.filter
}).then(function(response) {
$scope.questionCount = response.data.count;
return response.data.questions;
});
}
});
};
Run Code Online (Sandbox Code Playgroud)
如果我这样做,那很好.但那是因为我硬编码了total,这显然没有意义.如果我做
return $http.get("/api/questions", {
params: $scope.filter
}).then(function(response) {
params.total(response.data.count);
$scope.questionCount = response.data.count;
return response.data.questions;
});
Run Code Online (Sandbox Code Playgroud)
然后它出于某种原因两次ng-table触发http请求.那么正确的方法是什么?
我有一个使用ngTable显示在表上的对象列表.我的对象看起来像:
obj {label:string,
nestObj{nestLabel:string
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我想允许对字段'label'和'nestObject.label'进行排序和过滤.我试过这个:
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10,
filter: {
label='',
nestObj.label=''
},
sorting: {
label: 'asc',
nestObj.label: 'asc'
}
}, {
total: data.length, // length of data
getData: function($defer, params) {
// use build-in angular filter
var filteredData = params.filter() ?
$filter('filter')(data, params.filter()) :
data;
var orderedData = params.sorting() ?
$filter('orderBy')(filteredData, params.orderBy()) :
data;
params.total(orderedData.length); // set total for recalc pagination
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * …Run Code Online (Sandbox Code Playgroud) 我有3个执行类似任务的控制器:
它们每个都是唯一的(尽管它们具有相似的功能)。但是,它们都从定义相同的$scope变量开始:
app.controller("PastController", function ($scope) {
$scope.Outages = "";
$scope.loading = 0;
$scope.nothing = 0;
$scope.error = 0;
//--- code continues ---//
});
app.controller("CurrentController", function ($scope) {
$scope.Outages = "";
$scope.loading = 0;
$scope.nothing = 0;
$scope.error = 0;
//--- code continues ---//
});
app.controller("FutureController", function ($scope) {
$scope.Outages = "";
$scope.loading = 0;
$scope.nothing = 0;
$scope.error = 0;
//--- code continues ---//
});
Run Code Online (Sandbox Code Playgroud)
我可以使用服务或工厂在一个地方初始化这些变量,而不用重复代码吗?
我通过服务上传文件:
var addFile = function(files) {
var deferred = $q.defer();
var fd = new FormData();
fd.append("file", files[0]);
$http.post("/files", fd, {
***
})
.success(function(data, status, headers, config) {
***
})
.error(function(err, status) {
***
});
***
};
Run Code Online (Sandbox Code Playgroud)
在控制器中我有类似的东西:
uplService.addFile($scope.files).then(function(url) {
$scope.news.Photo = url;
});
Run Code Online (Sandbox Code Playgroud)
并在HTML视图中:
<input type="file" name="file" onchange="angular.element(this).scope().photoChanged(this.files)" />
Run Code Online (Sandbox Code Playgroud)
在此之前我上传了文件,当我选择文件时它直接进入服务器,但现在我需要在我选择它时以我的形式显示它,但是稍后上传,我在网上看到的只是使用指令,但是如何在不使用指令的情况下组织它?
我刚刚上传了一个新版本的代码到我的服务器并得到了这个错误,我无法理解,也不知道如何解决 - 我没有更改datetime2 - 我的代码语法中甚至没有这个词.你知道那是什么意思吗?
执行命令定义时发生错误.有关详细信息,请参阅内部异常
InnerException:System.ArgumentException:正在使用的SQL Server版本不支持数据类型"datetime2".
at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC [] rpcArray,Int32 timeout,Boolean inSchema,SqlNotificationRequest notificationRequest,TdsParserStateObject stateObj,Boolean isCommandProc)
在System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async)
在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method,DbAsyncResult result)
在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method)
在System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior,String method)
在System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior行为)
在System.Data.Common.DbCommand.ExecuteReader(CommandBehavior行为)
在System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior behavior)
sql entity-framework entity-framework-4 entity-framework-4.1
<html>
<body>
Date: <input type="text" id="txt" placeholder=" "/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我应该在placehoder引号内指定什么,以便可以在文本框中查看当前日期