NPM安装angularjs,然后在我的应用程序中需要angularjs

npm to install angularjs, then require angularjs in my application

本文关键字:angularjs 应用程序 我的 安装 然后 NPM      更新时间:2023-09-26

我想做的是非常基本的。我想安装AngularJS v1.5。X使用NPM,然后让它可供我在我的应用程序中使用。我看到的所有教程都是从angularjs.org下载Angular版本,然后把它包含在<script></script>标签的index.html中。但是我想使用npm来安装AngularJS,然后让它可以在我的index.html中使用,就像一个真正的开发人员可能会做的那样!

这些是我运行过的命令。

$ 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

这是我的基本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"
}

我创建了一个index.js,但我把它留空。然后,我在index.html中添加了一个src标签,以包括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>

我的表达式只是写{{ 5 + 5 }}而不是10。我哪里走错了?

通过

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

虽然我使用的是bower,检查angularJS文件在安装后的位置通过npm

或使用requireJS

npm只是存储库中前端库的管理器,而不是用于将其包含到webapp中的