Skip to content

Commit 3028163

Browse files
Beginning angular2-aspnet NPM package
1 parent 2261c99 commit 3028163

7 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules/
2+
/dist/
3+
/bundles/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/src/
2+
/tsconfig.json
3+
/build.js
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// -------------
2+
// No need to invoke this directly. To run a build, execute:
3+
// npm run prepublish
4+
// -------------
5+
6+
var Builder = require('systemjs-builder');
7+
var builder = new Builder('./');
8+
builder.config({
9+
defaultJSExtensions: true,
10+
paths: {
11+
'angular2-aspnet': 'dist/Exports',
12+
'angular2-aspnet/*': 'dist/*'
13+
},
14+
meta: {
15+
'angular2/*': { build: false }
16+
}
17+
});
18+
19+
var entryPoint = 'dist/Exports';
20+
var tasks = [
21+
builder.bundle(entryPoint, './bundles/angular2-aspnet.js'),
22+
builder.bundle(entryPoint, './bundles/angular2-aspnet.min.js', { minify: true })
23+
];
24+
25+
Promise.all(tasks)
26+
.then(function() {
27+
console.log('Build complete');
28+
})
29+
.catch(function(err) {
30+
console.error('Build error');
31+
console.error(err);
32+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "angular2-aspnet",
3+
"version": "0.0.1",
4+
"description": "Helpers for Angular 2 apps built on ASP.NET",
5+
"main": "./dist/Exports",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"prepublish": "tsc && node build.js"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/aspnet/NodeServices/tree/master/Microsoft.AspNet.AngularServices"
13+
},
14+
"typings": "dist/Exports",
15+
"author": "Microsoft",
16+
"license": "Apache-2.0",
17+
"peerDependencies": {
18+
"angular2": "^2.0.0-alpha.44"
19+
},
20+
"devDependencies": {
21+
"systemjs-builder": "^0.14.11",
22+
"typescript": "^1.7.3"
23+
}
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Validation';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { ControlGroup } from 'angular2/angular2';
2+
import { Response } from 'angular2/http';
3+
4+
export class Validation {
5+
6+
public static showValidationErrors(response: ValidationErrorResult | Response, controlGroup: ControlGroup): void {
7+
if (response instanceof Response) {
8+
var httpResponse = <Response>response;
9+
response = <ValidationErrorResult>(httpResponse.json());
10+
}
11+
12+
// It's not yet clear whether this is a legitimate and supported use of the ng.ControlGroup API.
13+
// Need feedback from the Angular 2 team on whether there's a better way.
14+
var errors = <ValidationErrorResult>response;
15+
Object.keys(errors || {}).forEach(key => {
16+
errors[key].forEach(errorMessage => {
17+
// This in particular is rough
18+
if (!controlGroup.controls[key].errors) {
19+
(<any>controlGroup.controls[key])._errors = {};
20+
}
21+
22+
controlGroup.controls[key].errors[errorMessage] = true;
23+
});
24+
});
25+
}
26+
27+
}
28+
29+
export interface ValidationErrorResult {
30+
[propertyName: string]: string[];
31+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es5",
5+
"sourceMap": false,
6+
"declaration": true,
7+
"noLib": false,
8+
"outDir": "./dist"
9+
},
10+
"exclude": [
11+
"node_modules"
12+
]
13+
}

0 commit comments

Comments
 (0)