angularjs 简单笔记
最近项目使用angularjs1.5,由于之前没有接触过angularjs,开发时磕磕绊绊,现在把开发时遇到的一些问题记录下来,一遍日后查找 1、获取当前web的根路径,js代码 var ctx = function() {
var path = window.location.href;
var pathName = window.location.pathname;
var hostPath = path.substring(0,path.indexOf(pathName))
var projectName = pathName.substring(0,pathName.substring(1).indexOf('/') + 1);
return (hostPath + projectName);
}
2、angularjs url带参数跳转 .state("tip-off-detail",{
params:{"id":null},url: "/tip-off-detail",templateUrl: "main/home/tip-off-detail.html"
})
跳转的位置代码替换为如下(增加()及之间的内容): ui-sref="tip-off-detail({id:publicReport.id})"
3、angularjs使用checkbox <input type="checkbox" ng-repeat="item in checkBoxs" ng-model="item.checked">{{item.text}}
ng-controller中如下定义: $scope.checkBoxs = [ {
"checked" : true,"text":"..."
},...];
4、angularjs使用radio 5、angularjs使用file上传 <input type="file" id="fileInput" onchange="angular.element(this).scope().uploadFile(this)">
可以在uploadFile中写文件上传代码,使用formdata上传时代码如下: $scope.uploadFile = function(e) {
var formdata = new FormData(); // 初始化一个FormData实例
formdata.append('file',e.files[0]); // file就是图片或者其他你要上传的formdata
$http.post(ctx() + "/common/upload",formdata,{
transformRequest : angular.identity,headers : {
'Content-Type' : undefined
}
}).success(function(data) {
}).error(function() {
});
}
6、ng-click不起作用 7、$http参数 8、主动使得ng-click失效 9、ioinc在ion-content标签下 ng-model失效的解决方案 这是由于ioinc的 scope与controller中的scope不是同一个scope导致的 可以在controller中使用 model={}先定义,在绑定的地方使用 model.attr的方式引用 或者 在绑定时使用$parent.attr (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |