I'm trying to integrate the XRegExp library into an Angular2 application using TypeScript.
After successfully installing XRegExp as a node.js module, I am facing issues with getting
var unicodeWord = XRegExp("^\\pL+$");
to function within a component method.
(How can I properly reference the JS library in TypeScript? How do I go about loading the node.js module in my Angular project?)
UPDATE
In my typings.json file:
{
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2",
"jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#d594ef506d1efe2fea15f8f39099d19b39436b71",
"xregexp": "github:DefinitelyTyped/DefinitelyTyped/xregexp/xregexp.d.ts"
}
}
Within the <head>
tag of my index.html:
<head>
<title>Amadeus</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 1. Load libraries -->
<!-- Required polyfills for IE -->
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
paths: {
xregexp: 'node_modules/xregexp/src/xregexp.js'
},
packages: {
angular_components: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('angular_components/ignition')
.then(null, console.error.bind(console));
</script>
</head>
For ignition.ts:
import {bootstrap} from 'angular2/platform/browser'
import {AmadeusComponent} from './amadeus/amadeus.component'
bootstrap(AmadeusComponent);
And in amadeus.component.ts:
import {Component} from 'angular2/core';
import {XRegExp} from 'xregexp';
@Component({
selector: 'amadeus',
templateUrl: 'angular_components/amadeus/amadeus.component.ahtml'
})
export class AmadeusComponent {
constructor(){
console.log(XRegExp); // undefined
}
}