控制器,带状态

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({
&nbsp; &nbsp; method: 'get',
&nbsp; &nbsp; url: 'http://camnpr.com/getAPI/',
&nbsp; &nbsp; params:{id: 1},
&nbsp; &nbsp; headers: {'x-camnpr-uid': '1000'}//可以加入任意的头信息
});

post请求

$http({
&nbsp; &nbsp; method: 'post',
&nbsp; &nbsp; url: 'http://camnpr.com/postAPI/',
&nbsp; &nbsp; data:'id=1&referrer=camnpr.com', // 这里是字符串,格式请注意,同时我们可以使用 $.param({id:1, referrer: 'camnpr.com'})来获取等价的形式。
&nbsp; &nbsp; // Form Data获取方式 Request.Form['id'] 。
&nbsp; &nbsp; //这是加'Content-Type': 'application/x-www-form-urlencoded',的功劳。
&nbsp; &nbsp; // 若不加'Content-Type',则:Request Payload:id=1&referrer=camnpr.com
&nbsp; &nbsp; // data: {id: 1, referrer: 'camnpr.com'}, // 是对象,那么 Form Data的数据是:{"id":1,"referrer":"camnpr.com"}:
&nbsp; &nbsp; 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){
&nbsp; &nbsp; if(item.checked){
&nbsp; &nbsp; &nbsp; &nbsp; ids+=item.value+',';
&nbsp; &nbsp; }
});

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、获取元素等的更多相关文章

  1. 用js 获取url 参数 页面跳转 ? 后的参数

    记得之前在原来的公司写过这个东西,但是还是忘记怎么接住参数了,只知道怎么把id传过去! 问了身边的大佬 他首先推荐了我一个链接是别人写好的方法 附上链接地址:http://blog.csdn.net/ ...

  2. 开发中常用Fel的写法

    直接看代码吧: package javademo; import java.util.HashMap;import java.util.Map; import com.greenpineyu.fel. ...

  3. 路由传值及获取参数,路由跳转,路由检测,this.$route.query和this.$route.params接收参数,HttpGet请求拼接url参数

    配置动态路由参数id: routes: [ // 动态路径参数 以冒号开头 { path: '/user/:id', component: User } ] html路由跳转: <router- ...

  4. angular6 路由拼接查询参数如 ?id=1 并获取url参数

    angular6 路由拼接查询参数如 ?id=1 并获取url参数 路由拼接参数: <div class="category-border" [routerLink]=&qu ...

  5. NC65在日常开发中常用的代码写法

    标题 NC65开发相关代码 版本 1.0.1 作者 walton 说明 收集NC在日常开发中常用的代码写法,示例展示 1.查询 1.1 通过BaseDAO查询结果集并转换 //通过BaseDAO进行查 ...

  6. Angularjs中使用$location获取url参数时,遇到的坑~~~

    今天在开发时候,需要用到Angularjs1.4.6获取url参数,网上查了一下,有部分文章提到用$location来获取.大致方法如下 var app = angular.module('myApp ...

  7. 依赖注入及AOP简述(十)——Web开发中常用Scope简介 .

    1.2.    Web开发中常用Scope简介 这里主要介绍基于Servlet的Web开发中常用的Scope. l        第一个比较常用的就是Application级Scope,通常我们会将一 ...

  8. Android源码浅析(四)——我在Android开发中常用到的adb命令,Linux命令,源码编译命令

    Android源码浅析(四)--我在Android开发中常用到的adb命令,Linux命令,源码编译命令 我自己平时开发的时候积累的一些命令,希望对你有所帮助 adb是什么?: adb的全称为Andr ...

  9. Java开发中常用jar包整理及使用

    本文整理了我自己在Java开发中常用的jar包以及常用的API记录. <!-- https://mvnrepository.com/artifact/org.apache.commons/com ...

随机推荐

  1. ulimit用法

    ulimit -a:显示当前所有的资源限制 -c:core文件大小 -f:设置创建文件的最大值 -n:设置内核可以同时打开的文件描述符的最大值 -p:设置管道缓冲区的最大值 -s:设置堆栈的最大值 - ...

  2. C语言对齐、补齐

    加快CPU读取数据的速度 aligned(n) 让所作用的结构成员对齐在n字节自然边界上.如果结构中有成员的长度大于n,则按照最大成员的长度来对齐 struct s { char c; int i; ...

  3. string leetcode-6.ZigZag

    6. ZigZag Conversion 题面 The string "PAYPALISHIRING" is written in a zigzag pattern on a gi ...

  4. MYSQL的操作命令

    一.御前 1 win+R  DOS 输入 net start mtsql 和 net stop mysql 启动和停止Mysql 服务,也可通过计算机——管理——服务和应用程序——服务——MYSQL— ...

  5. [Selenium2+python2.7][Scrap]爬虫和selenium方式下拉滚动条获取简书作者目录并且生成Markdown格式目录

    预计阅读时间: 15分钟 环境: win7 + Selenium2.53.6+python2.7 +Firefox 45.2  (具体配置参考 http://www.cnblogs.com/yoyok ...

  6. CentOS 7 根目录分区扩容

    查看现有磁盘信息,可以看出根分区有96G [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mappe ...

  7. 11_Azkaban案例实践4_Command操作MapReduce

    MAPREDUCE任务 Mr任务依然可以使用command的job类型来执行 1.创建job描述文件,及mr程序jar包(示例中直接使用hadoop自带的example jar) # mrwc.job ...

  8. python基础应用---列表应用

    列表:列表用[]来表示 names = ['wang', 'yuan', 'yang', 'china', 'french', 'wang'] #列表增加 names.append('zhang') ...

  9. ubuntu---github下载太慢的解决办法

    git clone --recursive https://github.com/tensorflow/tensorflow  下载太慢了,20:05-21:17 才下载了17%,等的太急人了. ** ...

  10. NLP传统基础(2)---LDA主题模型---学习文档主题的概率分布(文本分类/聚类)

    一.简介 https://cloud.tencent.com/developer/article/1058777 1.LDA是一种主题模型 作用:可以将每篇文档的主题以概率分布的形式给出[给定一篇文档 ...