6

I want to use collections.js in my typescript Angular2 project. I want to start with multimap. There's no @types/collections package and there's no collections.js in typings.

When I write

const MultiMap = require('collections/multi-map')

I got "NoProviderError for PlatformRef" in Agnular2.

6
  • Yes, that's where I started. @types/collections is not in the npm registry. Commented Mar 23, 2017 at 9:52
  • Do you also have a definition for require function somewhere? Commented Mar 23, 2017 at 10:30
  • No, I dont think so. I'm using github.com/AngularClass/angular2-webpack-starter as a startet kit. Commented Mar 23, 2017 at 10:31
  • Yes, I can see that they include "node" typings in their tsconfig.json Commented Mar 23, 2017 at 10:36
  • I dont understand why I getting this NoProviderError in case i require "collections/multi-map" Commented Mar 23, 2017 at 10:40

1 Answer 1

8

An error NoProviderError is caused by the fact that collection.js library changes the way how built-in primitives work, particularly Array.

Internally, zone.js (which is a part of Angular) invokes Array.from with an instance of MapIterator as an argument. In collections/shim-array.js file, this library overrides Array.from with an implementation, that doesn't work with MapIterator. In screenshot you can see, that it returns an empty array, while native implementation returns an array of 13 elements.

enter image description here

A conclusion is, that sadly you can't use Collections.js library with Angular.

Sign up to request clarification or add additional context in comments.

1 Comment

Wrong. You can still use it. Just override Array.from after the library 'collections' is imported in the entry point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.