最近想学习下angular,然后该文章记录了我在学习中遇到的问题
1、参照书上的例子
hello.html
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script src="controllers.js"></script>
</head>
<body>
<div ng-controller='HelloController'>
<p>{{greeting.text}},world</p>
</div>
</body>
</html>
controllers.js
function HelloController($scope){
$scope.greeting={text:'Hello'};
}
然后发现hello.html 报错了,没有出现预期的hello world
Error: [ng:areq] http://errors.AngularJS.org/1.4.8/ng/areq?p0=HelloCtrl&p1=not%20a%20function%2C%20got%20undefined
at Error (native)at http://localhost:8080/web/rs/angular.min.js:1:503
at qb (http://localhost:8080/web/rs/angular.min.js:1:8403)
at Qa (http://localhost:8080/web/rs/angular.min.js:1:8490
原因:
上网查询刚开始以为是我angular版本的问题,后来发现不是版本问题
Angular出现这种错误的原因,是由于没有在页面中使用模块引入controller导致的,修改内容如下:
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<script src="controllers.js"></script>
<script type="text/javascript">
var app=angular.module("app",[]);
app.controller("HelloController",HelloController);
</script>
</head>
<body>
<div ng-controller='HelloController'>
<p>{{greeting.text}},world</p>
</div>
</body>
</html>
2、因为需要nodeJs 快速编写一个简单的web服务器,在这里需要安装express,因为我是win7 64位 所以选择最新的msi安装,建议大家还是选择最新版本的,因为最新版本的已经内嵌了npm 这样不用自己再安装npm了,安装成功后接着在用npm install -g express的过程中出现了问题:
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "D:\\nodejs\\\\node.exe" "D:\\nodejs\\node_modules\\npm\\bin\\npm-
cli.js" "install" "-g" "express"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! syscall connect
npm ERR! network connect ETIMEDOUT
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settin
gs.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\HSUPENG\npm-debug.log
因为是在公司的电脑上安装的 所以重新设置了代理和代理密码
比如公司代理IP为10.10.10.1 端口 8090 用户名:sss 密码:sss
只需作如下设置:npm config set proxy http://10.10.10.1:8090
npm config set https-proxy http://proxy-domain.com:8090
set http_proxy_user=sss
set http_proxy_password=sss
然后再安装 npm install -g express