小编gxc*_*rke的帖子

找不到模块'angular2/angular2'

我正在开发一个带有angular2和gulp的节点应用程序.我已经编写了一个组件文件login.ts,如下所示:

import {Component, View} from 'angular2/angular2';
import {FormBuilder,  formDirectives } from 'angular2/forms';
@Component({
  selector: 'login',
  injectables: [FormBuilder]
})
@View({
  templateUrl: '/scripts/src/components/login/login.html',
  directives: [formDirectives]
})

export class login {

}
Run Code Online (Sandbox Code Playgroud)

我的bootstrap.ts文件是:

import {bootstrap} from 'angular2/angular2';

import {login} from './components/login/login';

bootstrap(login);
Run Code Online (Sandbox Code Playgroud)

但是当我编译这些文件时,它会给我以下错误:

client\bootstrap.ts(1,25): error TS2307: Cannot find module 'angular2/angular2'.
client\components\login\login.ts(1,31): error TS2307: Cannot find module 'angular2/angular2
client\components\login\login.ts(2,45): error TS2307: Cannot find module 'angular2/forms'.
Run Code Online (Sandbox Code Playgroud)

这是我的tsconfig.json:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "sourceMap": true,
        "watch": true,
        "removeComments": true,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": …
Run Code Online (Sandbox Code Playgroud)

node.js typescript angular

23
推荐指数
2
解决办法
1万
查看次数

如何在发送到视图之前修改控制器操作中的已发布表单数据?

我想在成功操作后呈现相同的视图(而不是使用RedirectToAction),但我需要修改呈现给该视图的模型数据.以下是一个人为的示例,演示了两种不起作用的方法:

    [AcceptVerbs("POST")]
    public ActionResult EditProduct(int id, [Bind(Include="UnitPrice, ProductName")]Product product) {
        NORTHWNDEntities entities = new NORTHWNDEntities();

        if (ModelState.IsValid) {
            var dbProduct = entities.ProductSet.First(p => p.ProductID == id);
            dbProduct.ProductName = product.ProductName;
            dbProduct.UnitPrice = product.UnitPrice;
            entities.SaveChanges();
        }

        /* Neither of these work */
        product.ProductName = "This has no effect";
        ViewData["ProductName"] = "This has no effect either";

        return View(product);
    }
Run Code Online (Sandbox Code Playgroud)

有谁知道实现这个的正确方法是什么?

asp.net-mvc

17
推荐指数
1
解决办法
1万
查看次数

c#代码似乎以无效方式进行优化,使得对象值变为null

我有以下代码,表现出一个奇怪的问题:

var all = new FeatureService().FindAll();
System.Diagnostics.Debug.Assert(all != null, "FindAll must not return null");
System.Diagnostics.Debug.WriteLine(all.ToString()); // throws NullReferenceException
Run Code Online (Sandbox Code Playgroud)

FindAll方法的签名是:

public List<FeatureModel> FindAll()
Run Code Online (Sandbox Code Playgroud)

单步执行代码我已经确认FindAll的返回值不为null,正如您从Assert中看到的那样,"all"变量不为null,但在下一行中它似乎为null.

调用ToString()方法时,问题不是特定于失败.在尝试追踪根本原因时,我将其简化为这个可重复的示例.

这可能是一个线索:在调试器中,变量"all"出现在Locals窗口中,其值为"无法获取本地或参数的值'all',因为它在此指令指针处不可用,可能是因为它已经被优化了."

我考虑尝试其他地方记录的方法之一来禁用代码优化,但这并不能真正解决问题,因为代码的发布版本仍然会被优化.

我在Visual Studio 2010中使用.NET 4.0.

有什么想法吗?

更新:根据请求,这是整个方法:

protected override List<FeatureModel> GetModels() {
    var all = new FeatureService().FindAll();
    var wr = new WeakReference(all);
    System.Diagnostics.Debug.Assert(all != null, "FindAll must not return null");
    System.Diagnostics.Debug.WriteLine(wr.IsAlive);
    System.Diagnostics.Debug.WriteLine(all.ToString()); // throws NullReferenceException
    return all;
}
Run Code Online (Sandbox Code Playgroud)

作为一个仅供参考,原始实施只是:

protected override List<FeatureModel> GetModels() {
    return new FeatureService().FindAll();
}
Run Code Online (Sandbox Code Playgroud)

我最初在调用方法中遇到了null异常.我发布的代码是在跟踪问题一段时间之后.

更新#2:根据要求,这是来自异常的堆栈跟踪:

 at FeatureCrowd.DomainModel.FeatureSearch.GetModels() in C:\Users\Gary\Documents\Visual Studio …
Run Code Online (Sandbox Code Playgroud)

c# nullreferenceexception

15
推荐指数
2
解决办法
1985
查看次数

要忽略的Git .Net文件

你对.net的Git最好的态度是什么?您忽略哪些文件而不添加到项目类型?

.net git

11
推荐指数
1
解决办法
3444
查看次数

使用EF4 CTP4代码第一种方法生成的多对多表中的命名约定

鉴于以下POCO课程:

public class Certification {
    public int Id { get; set; }
    public virtual ICollection<Employee> CertifiedEmployees { get; set; }
}

public class Employee {
    public int Id { get; set; }
    public virtual ICollection<Certification> Certifications { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

使用EF4 CTP4代码第一种方法创建数据库模型会创建所需的联结表:

CREATE TABLE [dbo].[Certifications_CertifiedEmployees](
[Certifications_Id] [int] NOT NULL,
[CertifiedEmployees_Id] [int] NOT NULL,
    ...
Run Code Online (Sandbox Code Playgroud)

但是,表名和列名称并不理想,因为它们是从关联的类属性名称生成的.我宁愿:

CREATE TABLE [dbo].[Employees_Certifications](
[Employee_Id] [int] NOT NULL,
[Certification_Id] [int] NOT NULL,
    ...
Run Code Online (Sandbox Code Playgroud)

有谁知道在这种情况下是否可以更改生成的列名称,还可以选择更改表名,以便Employees在Certifications之前?

谢谢,加里

many-to-many code-first entity-framework-4

8
推荐指数
2
解决办法
2004
查看次数

Angular 2从Observable <Xyz []>获取项目的方法

给出Angular 2服务中的以下Typescript:

getLanguages () {
    return this.http.get(this._languagesUrl)
        .map(res => <Language[]> res.json().data)
        .catch(this.handleError);
Run Code Online (Sandbox Code Playgroud)

在我需要从数组中查找特定项目的情况下,我很难使用它.例如,我不能执行以下操作,因为filter期望返回Observable<Language>而不是Observable<Language[]>返回.

getLanguages().filter(language => language.id == 3) // Error
Run Code Online (Sandbox Code Playgroud)

我感谢我的问题可能是我混合了同步和异步行为,因此我提供了我的用例:用户可以输入语言ID,我想显示相关的语言名称.我想利用getLanguages()Observable因为它已经在该项目的其他地方使用的结果.我还希望实现一些缓存,这样每次进行查找时都不会发出HTTP请求.

有什么想法吗?

rxjs typescript angular

8
推荐指数
2
解决办法
1万
查看次数

Angular 2 http结果的正确错误处理

我一直在使用angular.io文档中使用的http错误处理策略:

getHeroes () {
    return this.http.get(this._heroesUrl)
                    .map(res => <Hero[]> res.json().data)
                    .catch(this.handleError);
    }
    private handleError (error: Response) {
        console.error(error);
        return Observable.throw(error.json().error || 'Server error');
    }
}
Run Code Online (Sandbox Code Playgroud)

在某些情况下,我将收到204状态代码(无数据),而不是JSON响应.在这种情况下,错误处理程序不会被调用,直到无法通过解析的结果res.json(),所以传递到的HandleError错误是"error.json不是一个函数".

如何查询响应流以检查200(OK)状态代码或响应头内容类型"application/json",并通过更相关的错误消息发出错误处理程序的信号?

http rxjs angular

5
推荐指数
1
解决办法
1万
查看次数