thedanotto thedanotto - 5 months ago 9
AngularJS Question

npm to install angularjs, then require angularjs in my application

What I want to do is very basic. I want to install AngularJS v1.5.x using npm and then have it available for me to utilize within my application. All the tutorials I see out there are just downloading the Angular Version from angularjs.org then including it in their

index.html
in a
<script></script>
tag. But I want to use npm to install AngularJS and then make it available for me to use within my
index.html
like a real developer might do!

Here are the commands I've run.

$ npm init
$ npm install angular@1.5.7 --save
npm-angular-test@1.0.0 /Users/theDanOtto/Sites/Playground/npm-angular-test
└── angular@1.5.7


Here is my basic
package.json


{
"name": "npm-angular-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"angular": "^1.5.7"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}


I created an
index.js
, but I left it blank. I then added a src tag in my
index.html
to include
index.js
.

<!DOCTYPE html>
<html ng-app>
<head>
<title>Html</title>
<script src="index.js"></script>
</head>
<body>
<p>My first expression: {{ 5 + 5 }}</p>
</body>
</html>


My expression simply writes
{{ 5 + 5 }}
instead of
10
. Where am I headed wrong?

f7o f7o
Answer

Either include Angular.js via

<script type="text/javascript" src="node_modules/somefile.js"></script>

though i use bower, check were angularJS file is located after installing it via npm

or use requireJS

npm is only some manager for frontend libraries in your repository, not for including it into the webapp

Comments