1.angular JS在操作表单中的隐藏域的时候发现angularjs的模型无法绑定,比如:
<input type="hidden" name="someData" ng-model="data" />
解决方法:
有以下几种解决办法:
(1)<input type="hidden" name="someData" value="{{data}}" />
(2)<input type="hidden" name="someData" ng-value="data" />
2.mongoose 新增记录的方法:
参考:http://mongoosejs.com/docs/models.html
var Tank = mongoose.model('Tank', yourSchema);
var small = new Tank({ size: 'small' });
small.save(function (err) {
if (err) return handleError(err);
// saved!
})
// or
Tank.create({ size: 'small' }, function (err, small) {
if (err) return handleError(err);
// saved!
})
用save插入时,不能获取新增对象的_id属性,而且若model中定义了_id属性,会出现[Error: document must have an _id before saving];
3.angular js $http.get()方法
参考:http://www.cnblogs.com/liulangmao/p/3864954.html
基本语法:
$http.get('url',{}).success(function(data,status,headers,config){
}).error(function(data,status,headers,config){
})
$http.get接受两个参数:
(1)url: 请求的路径
(2)json对象: 请求参数配置,如 {params:{id:5}}
这样得到的实际路径就是url?id=5
$http.get返回的对象有两个回调方法:
(1)success: 请求成功的回调
(2)error: 请求失败的回调
这两个方法都有四个参数:
①data: 返回的数据(或错误)
②status: 响应的状态码
③headers: 这样一个函数,具体是什么暂时不详
function (name) {
if (!headersObj) headersObj = parseHeaders(headers);
if (name) {
return headersObj[lowercase(name)] || null;
}
return headersObj;
}
④congfig: 请求的配置对象
{
method: "GET",
url: "/api/user",
params: {id:5}
}
实例:
前端angular js
html:
复制代码
<!DOCTYPE html>
<html ng-app = 'HttpGet'>
<head>
<title>18.1 $http.get方法</title>
<meta charset="utf-8">
<script src="angular.js"></script>
<script src="script.js"></script>
</head>
<body>
<div ng-controller = "dataController">
<span>{{data}}</span>
</div>
</body>
js:
var httpGet = angular.module('HttpGet',[]);
httpGet.factory('getData',function($http,$q){
return function(){
var defer = $q.defer();
$http.get('/api/user').success(function(data,status,headers,congfig){
//console.log(status);
//console.log(headers);
//console.log(congfig);
defer.resolve(data);
}).error(function(data,status,headers,congfig){
defer.reject(data);
});
return defer.promise
}
});
httpGet.controller('dataController',function($scope,getData){
var promise = getData();
promise.then(function(data){
});
});
后端node:
var express = require('express');
var app = express();
app.use(express.static(__dirname+''));
var data = 'angularjs中的$http.get';
app.get('/api/user',function(req,res){
res.send(data)
});
app.listen(3000);
4.angular js 点击超链接a不能刷新页面
Have you by any chance configured your $locationProvider to html5Mode? If yes this would cause your problems. You could force it to always go to the url by adding target="_self" to your tag. Give it a shot.
你已经改变配置了你的 $locationProvider(特性有:hashPrefix、html5Mode) 为 html5Mode。如果这会造成你的问题。你可能不得不经常去的URL添加目标=“_self”您的标签。给它一个机会。
5.angular js $location获取url参数
// 带#号的url,看?号的url,见下面
url = http://qiaole.sinaapp.com?#name=cccccc
$location.absUrl();
// http://qiaole.sinaapp.com?#name=cccccc
$location.host();
// qiaole.sinaapp.com
$location.port();
// 80
$location.protocol();
// http
$location.url();
// ?#name=cccccc
// 获取url参数
$location.search().name;
// or
$location.search()['name'];
// 注:如果是这样的地址:http://qiaole.sinaapp.com?name=cccccc
var searchApp = angular.module('searchApp', []);
searchApp.config(['$locationProvider', function($locationProvider) {
$locationProvider.html5Mode(true);
}]);
searchApp.controller('MainCtrl', ['$scope', '$location', function($scope, $location) {
if ($location.search().keyword) {
$scope.keyword = $location.search().keyword;
}
}]);
6.angular js刷新页面
$state.go和$location.href有什么区别
前者不在浏览器中保存跳转前的网址,因此按返回键将无效 后者不存在这个问题 reload方法,强迫浏览器刷新当前页面 replace方法,通过指定URL替换当前缓存在历史里(客户端)的项目,因此当使用replace方法之后,你不能通过“前进”和“后退”来访问已经被替换的URL。 在实际应用的时候,重新刷新页面的时候,我们通常使用: location.reload() 或者是 history.go(0) 来做。。因为这种做法就像是客户端点F5刷新页面,所以页面的method=”post”的时候,会出现“网页过期”的提示。那是因为Session的安全保护机制。
个人尝试用 $state.go('movie.main',{},{reload:true});
刷新页面时无法刷新整个页面,只能刷新页面的一部分templateurl对应的部分,用location.reload()可刷新整个页面