angularJS

1.$location服务的使用
在angularjs的组件中定义,例如demo.js

module.controller('MainController', function($rootScope, $scope,$location){
$scope.urll=$location.search();
};

使用
假设URL为[url]http://192.168.139.215:8080/demo/#/drag?mid=null&yid=zouhuiying[/url]
在html中可以这样引用mid={{urll.mid}}&yid={{urll.yid}}
注:html中的onclick中不能引用angularjs的变量
可以用以下方式取值:

<div onclick="alert(this.innerHTML)" class="media-heading">{{user.name}}</div>


双向数据绑定
如果绑定的数据在子页面,要实现数据双向绑定要加入以下代码,在view中数据发生改变时,手动调用cha函数
$scope.safeApply = function(fn) {
var phase = this.$root.$$phase;
console.log(phase+"---phase");
if (phase == '$apply' || phase == '$digest') {
if (fn && (typeof(fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};
$rootScope.cha = function() {
console.log("cha");
$scope.safeApply(function () {
$scope.greeting = document.getElementById("thism").value;
});
}


parseInt() 把字符串转化为int


使数组每次新加的元素放在数组首部
var t;
for(var i=0; i<$scope.notices.length-1; i++)
{
j=$scope.notices.length-1;
t=$scope.notices[i];
$scope.notices[i]=$scope.notices[j];
$scope.notices[j]=t;

};



$http服务的使用
$http.get('http://192.168.139.215:8080/p/usermenu.jsp').success(function(data) {
  $scope.people = data;
}).then(function(data){
...//成功后执行的函数,不加then时会异步执行这段代码
};



$location服务的使用
$scope.people=$resource("http://192.168.139.215\\:8080/p/usermenu.jsp");
$scope.people.query()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值