我正在尝试将输入字段中的值绑定到ng-click上的方法参数.这是我得到的,但它不起作用,我不太确定是否可以这样做?:
<input type="text" name="name" value="{{post.PostId}}" />
<button ng-click="getById(post.PostId)"></button>
<h1>{{post.Title}}</h1>
$scope.getById = function (id) {
console.log(id);
return $http.get('/api/Post/' + id);
}
Run Code Online (Sandbox Code Playgroud) html javascript angularjs angularjs-ng-click angularjs-ng-model
在我的angularjs应用程序上获取以下消息:
Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- Item
http://errors.angularjs.org/1.3.8/$injector/unpr?p0=%24resourceProvider%20%3C-%20%24resource%20%3C-%20Item
at http://localhost:49717/Scripts/angular.js:63:12
at http://localhost:49717/Scripts/angular.js:3994:19
at Object.getService [as get] (http://localhost:49717/Scripts/angular.js:4141:39)
at http://localhost:49717/Scripts/angular.js:3999:45
at getService (http://localhost:49717/Scripts/angular.js:4141:39)
at Object.invoke (http://localhost:49717/Scripts/angular.js:4173:13)
at Object.enforcedReturnValue [as $get] (http://localhost:49717/Scripts/angular.js:4035:37)
at Object.invoke (http://localhost:49717/Scripts/angular.js:4182:17)
at http://localhost:49717/Scripts/angular.js:4000:37
at getService (http://localhost:49717/Scripts/angular.js:4141:39) <div ng-view="" class="ng-scope">
Run Code Online (Sandbox Code Playgroud)
我的app.js.
'use strict';
var SalesApp = angular.module('SalesApp', ['ngRoute']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/', { controller: ItemCtrl, templateUrl: 'item.html' }).
otherwise({ redirectTo: '/' });
}]);
SalesApp.factory('Item', function ($resource) {
return $resource('/api/Item/:iid', { iid: '@iid' }, { …Run Code Online (Sandbox Code Playgroud) 目前的问题是"主屏幕"显示,但立即关闭,我不明白为什么.这是处理新表单的关闭和打开的代码段.
编辑:.这是指Login.cs(对不起)
if(templogin == true && permission.Equals("1"))
{
mainScreen.IsAdmin();
this.Close();
mainScreen.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud) 我目前有这个代码,我知道如何打印行,但我无法弄清楚如何获取我的列标题?我不想使用我已经注释掉的解决方案,因为我想使代码通用,以便我也可以将它用于其他列表.
static DataTable ConvertListToDataTable(List<List<string>> list)
{
// New table.
DataTable table = new DataTable();
/* table.Columns.Add("Employee ID");
table.Columns.Add("First Name");
table.Columns.Add("Last Name");
table.Columns.Add("Job Title");
table.Columns.Add("Address");
table.Columns.Add("City");
*/
foreach(List<string> row in list) {
table.Rows.Add(row.ToArray());
}
return table;
}
Run Code Online (Sandbox Code Playgroud) 我一直在研究这种方法一段时间,并试图弄清楚它是如何工作的.这显然适用于返回完美的对象列表.但我目前无法弄清楚的是我将如何检索单个对象,例如"Employee e"而不是"List"?
public static List<T> DataTableToList<T>(this DataTable table) where T : class, new()
{
try
{
List<T> list = new List<T>();
foreach (var row in table.AsEnumerable())
{
T obj = new T();
foreach (var prop in obj.GetType().GetProperties())
{
try
{
PropertyInfo propertyInfo = obj.GetType().GetProperty(prop.Name);
propertyInfo.SetValue(obj, Convert.ChangeType(row[prop.Name], propertyInfo.PropertyType), null);
}
catch
{
continue;
}
}
list.Add(obj);
}
return list;
}
catch
{
return null;
}
}
Run Code Online (Sandbox Code Playgroud) 当我29/07/1990在文本框中书写时,此代码似乎不起作用.它总是转到else语句.
string date = tbDate.Text;
DateTime Test;
if (DateTime.TryParseExact(date, "MM/dd/yyyy", null, DateTimeStyles.None, out Test) == true) {
Console.WriteLine("Date OK");
} else {
Console.WriteLine("Date Not OK");
}
Run Code Online (Sandbox Code Playgroud) c# ×4
angularjs ×2
javascript ×2
.net ×1
datatable ×1
generics ×1
html ×1
list ×1
reflection ×1
winforms ×1