AngularJS开发中常用的写法,如:获取URL参数、路由跳转、$http、获取元素等
控制器,带状态
app.controller('editCtrl', ['$http', '$location', '$rootScope', '$scope', '$state', '$stateParams', function($http, $location, $rootScope, $scope, $state, $stateParams){
// 上边声明添加显示的依赖注入,是为了防止,压缩(如UglifyJS)时改变function里的参数名,造成功能引用失败。推荐r.js压缩
// do something...
}
获取路由的参数
$stateParams.id // #/camnpr/editCtrl?id=1
跳转路由状态
$state.go('camnpr.appManager'); // 跳转后的URL: #/camnpr/appManager
$location.path('camnpr/appManager'); // 功能也是跳转的
ui-router扩展的跳转方式
<a ui-sref="camnpr.appManager">跳转</a> // 需要angular-ui-router
在ng-repeat里显示序号: $index // 这个是从0计数的。
get请求
$http({
method: 'get',
url: 'http://camnpr.com/getAPI/',
params:{id: 1},
headers: {'x-camnpr-uid': '1000'}//可以加入任意的头信息
});
post请求
$http({
method: 'post',
url: 'http://camnpr.com/postAPI/',
data:'id=1&referrer=camnpr.com', // 这里是字符串,格式请注意,同时我们可以使用 $.param({id:1, referrer: 'camnpr.com'})来获取等价的形式。
// Form Data获取方式 Request.Form['id'] 。
//这是加'Content-Type': 'application/x-www-form-urlencoded',的功劳。
// 若不加'Content-Type',则:Request Payload:id=1&referrer=camnpr.com
// data: {id: 1, referrer: 'camnpr.com'}, // 是对象,那么 Form Data的数据是:{"id":1,"referrer":"camnpr.com"}:
headers: {'Content-Type': 'application/x-www-form-urlencoded', 'x-camnpr-uid': '1000'}
});
根据selector获取元素
angular.element('.is_select') // [<input type="checkbox" value="1" class="is_select">]
循环获取并操作
angular.forEach(document.getElementsByClassName('is_select'), function(item, index){
if(item.checked){
ids+=item.value+',';
}
});
ng-click里带当前的a,button等的事件
<button ng-click="camnpr.submitAdd($event)" class="btn btn-primary ladda-button" data-style="zoom-in"><span class="ladda-label">提交</span></button> // $event.target.currentTarget
AngularJS开发中常用的写法,如:获取URL参数、路由跳转、$http、获取元素等的更多相关文章
- 用js 获取url 参数 页面跳转 ? 后的参数
记得之前在原来的公司写过这个东西,但是还是忘记怎么接住参数了,只知道怎么把id传过去! 问了身边的大佬 他首先推荐了我一个链接是别人写好的方法 附上链接地址:http://blog.csdn.net/ ...
- 开发中常用Fel的写法
直接看代码吧: package javademo; import java.util.HashMap;import java.util.Map; import com.greenpineyu.fel. ...
- 路由传值及获取参数,路由跳转,路由检测,this.$route.query和this.$route.params接收参数,HttpGet请求拼接url参数
配置动态路由参数id: routes: [ // 动态路径参数 以冒号开头 { path: '/user/:id', component: User } ] html路由跳转: <router- ...
- angular6 路由拼接查询参数如 ?id=1 并获取url参数
angular6 路由拼接查询参数如 ?id=1 并获取url参数 路由拼接参数: <div class="category-border" [routerLink]=&qu ...
- NC65在日常开发中常用的代码写法
标题 NC65开发相关代码 版本 1.0.1 作者 walton 说明 收集NC在日常开发中常用的代码写法,示例展示 1.查询 1.1 通过BaseDAO查询结果集并转换 //通过BaseDAO进行查 ...
- Angularjs中使用$location获取url参数时,遇到的坑~~~
今天在开发时候,需要用到Angularjs1.4.6获取url参数,网上查了一下,有部分文章提到用$location来获取.大致方法如下 var app = angular.module('myApp ...
- 依赖注入及AOP简述(十)——Web开发中常用Scope简介 .
1.2. Web开发中常用Scope简介 这里主要介绍基于Servlet的Web开发中常用的Scope. l 第一个比较常用的就是Application级Scope,通常我们会将一 ...
- Android源码浅析(四)——我在Android开发中常用到的adb命令,Linux命令,源码编译命令
Android源码浅析(四)--我在Android开发中常用到的adb命令,Linux命令,源码编译命令 我自己平时开发的时候积累的一些命令,希望对你有所帮助 adb是什么?: adb的全称为Andr ...
- Java开发中常用jar包整理及使用
本文整理了我自己在Java开发中常用的jar包以及常用的API记录. <!-- https://mvnrepository.com/artifact/org.apache.commons/com ...
随机推荐
- 使用私有api实现自己的iphone桌面,并根据app的使用次数对app排序
使用<iphone SprintBoard部分私有API总结>中提到的api,除了能对app运行次数进行监控以外,还可以实现自己的iphone桌面,并根据app 的使用次数对app图标进行 ...
- perl语言的线程使用
参考的教程链接是 https://www.cnblogs.com/migrantworkers/p/6973459.html 1.Perl 多线程的使用,join 和 detach 的区别 ,join ...
- Centos6.5 自带的Python2.6.6 如何安装setuptools和pip
setuptools-36.7.1 [root@ ]# wget https://files.pythonhosted.org/packages/a9/23/720c7558ba6ad3e0f5ad0 ...
- redis集群安装2
概要:本文主要介绍如何在Centos7中单机搭建redis集群三主三从,按照本文绝对可以实现该需求,至于先搭建单机版主要为了方便理解redis集群,为下一步开发或生产上redis集群做铺垫.同时本 ...
- 【问题】Difference between ">/dev/null 2>&1" and "2>&1 >/dev/null"
https://www.unix.com/shell-programming-and-scripting/125947-difference-between-dev-null-2-1-2-1-dev- ...
- Vs2017 NetCode Mvc EF Mysql 整合1
1 运行环境 vs2017 NetCode2.0 2 NuGet MySql.Data.EntityFrameworkCore 8.0.18 3 源代码 https://github.c ...
- tensorflow实战笔记(19)----使用freeze_graph.py将ckpt转为pb文件
一.作用: https://blog.csdn.net/yjl9122/article/details/78341689 这节是关于tensorflow的Freezing,字面意思是冷冻,可理解为整合 ...
- c++初步认识
经过漫长的C学习终于踏入C++的知识库当中了,还是保持以前的习惯会一步步通过写博客的形式来记录点滴学习记录,这种学习方式是相当慢的,但是对我来说是最踏实的,不浮躁,一步一个脚印.C++是一门啥语言呢, ...
- SP703 SERVICE - Mobile Service[DP]
题意翻译 Description 一个公司有三个移动服务员.如果某个地方有一个请求,某个员工必须赶到那个地方去(那个地方没有其他员工),某一时刻只有一个员工能移动.只有被请求后,他才能移动,不允许在同 ...
- Spring-使用JAVA的方式配置Spring-代理模式
9.使用Java的方式配置Spring 我们现在要完全不使用Spring的xml配置了,全权交给Java来做! JavaConfig是Spring的一个子项目,在Spring4之后,它成为了一个核心功 ...