`

angularJS

阅读更多
1.$location服务的使用
在angularjs的组件中定义,例如demo.js
 
module.controller('MainController', function($rootScope, $scope,$location){
$scope.urll=$location.search();
  };

使用
假设URL为http://192.168.139.215:8080/demo/#/drag?mid=null&yid=zouhuiying
在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()




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics