【问题标题】:npm to install angularjs, then require angularjs in my applicationnpm 安装 angularjs,然后在我的应用程序中需要 angularjs
【发布时间】:2016-06-28 06:55:18
【问题描述】:

我想做的是非常基本的。我想使用 npm 安装 AngularJS v1.5.x,然后让我在我的应用程序中使用它。我看到的所有教程都只是从 angularjs.org 下载 Angular 版本,然后将其包含在 index.html<script></script> 标签中。但我想使用 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。我哪里错了?

【问题讨论】:

    标签: javascript angularjs npm


    【解决方案1】:

    要么通过 Angular.js 包含

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

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

    或使用requireJS

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

    【讨论】:

    • 在这种情况下“/node_modules/somefile.js”应该是“/node_modules/angular/angular.js”(或“/bower_components/angular/angular.js”当使用凉亭)根据@ 987654322@
    猜你喜欢
    • 1970-01-01
    • 2014-04-25
    • 2015-08-17
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    • 2020-08-01
    相关资源
    最近更新 更多