andreaferretti / paths-js

Generate SVG paths for geometric shapes :bar_chart:
http://andreaferretti.github.io/paths-js-react-demo/
Apache License 2.0
1.72k stars 84 forks source link

Angularjs, ReferenceError: require is not defined #12

Closed goids closed 10 years ago

goids commented 10 years ago

I'm working in a application on angularjs. and when I type this code var Pie = require('paths/pie'); I get the javascript error. "ReferenceError: require is not defined", Why?

andreaferretti commented 10 years ago

There are various ways to use Paths.js. var Pie = require('paths/pie'); works when you use a library like Require.js to handle your modules. If instead you work on node (server side) you can add paths-js as a dependency in npm and then use var Pie = require('paths-js/pie);.

In your case I guess you are not using a module system, so you can add the file dist/global/paths.js directly in your html, something like <script src="lib/paths/dist/global/paths.js"></script> (the actual path will depend on your directory structure).

You can see an example of this on this demo. The example is more complicated than you need, because in that demo I showcase the use of Paths.js with three different frameworks (Angular, React and Ractive), but you should be able to extract the part which involves Angular as a starting point. Let me know if you find any stumbling block.

goids commented 10 years ago

Ok, thanks.

andreaferretti commented 10 years ago

Ops, sorry, I forgot to add that when you add the global file, you fill find the modules namespaced under the paths variable: paths.Pie, paths.Sankey, paths.Path and so on