全部,
尝试绑定到模型上的函数时出现错误
我有以下组件、模型和 Html(对于这个例子都是假的)
export class TestModel {
public getSomeValue(): string {
return "Hello World";
}
}
Run Code Online (Sandbox Code Playgroud)
让我们假设 testModels 属性以某种方式获取它的数据。
@Component(...)
public class MyComponent {
public testModels: TestModel[];
ngOnInit() {
this.loadData();
}
public loadData(): void
{
this.http.get("...")
.map(r=>r.json as TestModel[]) // <--- I think now you've asked the question, I see the problem on this line
.subscribe(d=>this.testModels = d);
}
}
Run Code Online (Sandbox Code Playgroud)
现在在我的 html
<div *ngFor="let testModel of testModels">
<span>{{testModel.getSomeValue()}}</span> <!-- This fails -->
</div>
Run Code Online (Sandbox Code Playgroud)
这是完整的错误:
error_handler.js:48 EXCEPTION: Error in ./MyComponent …
我正在尝试在需要验证并具有FluentValidation提供的验证元数据的表单字段上自动呈现一个红色的星号。
我的工作方式占50%,但是使用When(....子句会引起一些问题。
一个简化的示例是:标记助手
public class NjordInputTagHelper : TagHelper
{
public override void Process(
TagHelperContext context,
TagHelperOutput output)
{
IValidator validator = _factory.GetValidator(For.Metadata.ContainerType);
if (validator == null)
{
return;
}
IValidatorDescriptor description = validator.CreateDescriptor();
IEnumerable<IPropertyValidator> propertyValidators = description.GetValidatorsForMember(For.Metadata.PropertyName);
if ((For.Metadata.ModelType != typeof(bool) && For.Metadata.IsRequired )
//|| propertyValidators.Any(p=> p is NotNullValidator || p is NotEmptyValidator )
)
{
//insert asterisk
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的验证人
public class MyValidator: AbstractValidator<MyModel>
{
public MyValidator()
{
When(x=>x.MyPropertyA != null, () =>
{
RuleFor(x=> x.MyPropertyB).NotEmpty(); …Run Code Online (Sandbox Code Playgroud) 当我说,Web API可以在OWIN和MVC 5上运行时,我是否正确?
所以在我的项目中,我仍然需要我的Global.asax public class WebApiApplication : System.Web.HttpApplication
目前我的owin Startup.cs看起来像这样:
public void Configuration(IAppBuilder app)
{
var httpConfig = new HttpConfiguration
{
};
WebApiConfig.Register(httpConfig);
app.UseWebApi(httpConfig);
app.UseCors(CorsOptions.AllowAll);
RouteConfig.RegisterRoutes(RouteTable.Routes);//MVC Routing
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Run Code Online (Sandbox Code Playgroud)
是RouteConfig.RegisterRoutes(RouteTable.Routes)吗?
每当我浏览任何MVC路线时,我都会获得404.
我可能希望通过网络发送数据包或某种请求,但不会发送任何特定的请求.机器或可能的多个机器将安装一个软件来监听此特定数据包或请求并作出响应.然后大型机服务器知道它有x个服务器来分享工作量.
我可以使用某种形式的UDP广播或TCP数据包来实现这种功能吗?我会用C#.NET来做这件事.
这个问题的最终结果是有一个主服务器有任务要完成但是喜欢在任何可用的机器上分享工作,但它永远不会知道任何关于它们的事情.它会发出请求说"我需要做一些工作"机器会响应像"我自由"+ IP地址然后主机将能够使用TCP连接来提供工作(我可以轻松实现这一部分) .我只需要通过网络进行初始盲请求.
我希望这是有道理的,如果我必须弄清楚另一种方式,所以主机知道所有的工人然后我会,但我不想也不会.
谢谢
史蒂夫
是否可以通过仅知道它的名称来手动解析组件?
我有一个字符串变量,它将包含一个组件的名称,让我们说"UserService"
我需要能够解决这种类型,我看过Injctor,我可以从文档中看到有一个resolve()和resolveAndCreate()(https://angular.io/docs/ts/latest/api/core/Injector-class.html)
但我没有Type.
谢谢
史蒂夫
编辑:尝试以下:
System.import("path/to/service").then(p=>{
var injector = Injector.resolveAndCreate([p[this.serviceName]]);//works
var serviceInstance = injector.get(p[this.serviceName]); //Fails with "No provider for Http! (UserService -> Http)".
});
Run Code Online (Sandbox Code Playgroud)
我有Http可用,它是在bootstrap期间提供的,这适用于应用程序的其他部分.
bootstrap(AppComponent, [
ROUTER_PROVIDERS, Http, HTTP_PROVIDERS, UrlBuilderService,
provide(LocationStrategy, { useClass: HashLocationStrategy }),
provide('notification', { useClass: NotificationService })
]);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
进一步编辑:
我现在称之为resolveAndCreate:
var injector = Injector.resolveAndCreate([p[this.serviceName], Http]);
Run Code Online (Sandbox Code Playgroud)
哪个失败了
没有ConnectionBackend的提供者!(UserService - > Http - > ConnectionBackend)
所以我称之为:
var injector = Injector.resolveAndCreate([p[this.serviceName], Http, …Run Code Online (Sandbox Code Playgroud) 所有,
当涉及到指令时,我对angularjs的理解是当你有一个像这样的隔离范围设置时:
scope: {
dataSource: '='
}
Run Code Online (Sandbox Code Playgroud)
在链接功能内: function(scope, ele, attr)
如果像这样使用,scope将有一个dataSource绑定到name我的控制器上的属性:
<my-element data-source='name'></my-element>
然而事实并非如此,这是一个例子:
http://jsfiddle.net/HB7LU/21879/
谢谢
史蒂夫
c# ×3
.net ×2
angular ×2
asp.net-mvc ×2
typescript ×2
.net-core ×1
angularjs ×1
networking ×1
owin ×1
systemjs ×1