控制器,带状态

  1. app.controller('editCtrl', ['$http', '$location', '$rootScope', '$scope', '$state', '$stateParams', function($http, $location, $rootScope, $scope, $state, $stateParams){
  2. // 上边声明添加显示的依赖注入,是为了防止,压缩(如UglifyJS)时改变function里的参数名,造成功能引用失败。推荐r.js压缩
  3.     // do something...
  4. }

获取路由的参数

  1. $stateParams.id // #/camnpr/editCtrl?id=1

跳转路由状态

  1. $state.go('camnpr.appManager'); // 跳转后的URL: #/camnpr/appManager
  2. $location.path('camnpr/appManager'); // 功能也是跳转的

ui-router扩展的跳转方式

  1. <a ui-sref="camnpr.appManager">跳转</a> // 需要angular-ui-router

ng-repeat里显示序号: $index // 这个是从0计数的。

get请求

  1. $http({
  2. &nbsp; &nbsp; method: 'get',
  3. &nbsp; &nbsp; url: 'http://camnpr.com/getAPI/',
  4. &nbsp; &nbsp; params:{id: 1},
  5. &nbsp; &nbsp; headers: {'x-camnpr-uid': '1000'}//可以加入任意的头信息
  6. });

post请求

  1. $http({
  2. &nbsp; &nbsp; method: 'post',
  3. &nbsp; &nbsp; url: 'http://camnpr.com/postAPI/',
  4. &nbsp; &nbsp; data:'id=1&referrer=camnpr.com', // 这里是字符串,格式请注意,同时我们可以使用 $.param({id:1, referrer: 'camnpr.com'})来获取等价的形式。
  5. &nbsp; &nbsp; // Form Data获取方式 Request.Form['id'] 。
  6. &nbsp; &nbsp; //这是加'Content-Type': 'application/x-www-form-urlencoded',的功劳。
  7. &nbsp; &nbsp; // 若不加'Content-Type',则:Request Payload:id=1&referrer=camnpr.com
  8. &nbsp; &nbsp; // data: {id: 1, referrer: 'camnpr.com'}, // 是对象,那么 Form Data的数据是:{"id":1,"referrer":"camnpr.com"}:
  9. &nbsp; &nbsp; headers: {'Content-Type': 'application/x-www-form-urlencoded', 'x-camnpr-uid': '1000'}
  10. });

  

根据selector获取元素

  1. angular.element('.is_select') // [<input type="checkbox" value="1" class="is_select">]

循环获取并操作

  1. angular.forEach(document.getElementsByClassName('is_select'), function(item, index){
  2. &nbsp; &nbsp; if(item.checked){
  3. &nbsp; &nbsp; &nbsp; &nbsp; ids+=item.value+',';
  4. &nbsp; &nbsp; }
  5. });

ng-click里带当前的a,button等的事件

  1. <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. JavaScript流程图(精简版)

    网址:https://www.processon.com/view/link/5db4f595e4b0c5553741c271 如果链接失效,请及时反馈(在评论区评论),博主会及时更新

  2. js的数据类型、函数、流程控制及变量的四种声明方式

    运算符 基本运算符 加 + 减 - 乘 * 除 / 取余 % 自增 ++ eg: 1++ 或 ++1 自减 -- eg: 1-- 或 --1 注:++或--写在前面表示优先级最高,先进行自增或者自减 ...

  3. 第三方应用如何在SAP Kyma上进行服务注册

    Jerry之前的公众号文章 什么?在SAP中国研究院里还需要会PHP开发?提到了一个SAP Kyma的应用场景: 旅行兼社交达人伊森,使用经过SAP Kyma扩展之后的WordPress这个网站来写博 ...

  4. umi model 注册

    model 分两类,一是全局 model,二是页面 model.全局 model 存于 /src/models/ 目录,所有页面都可引用:页面 model 不能被其他页面所引用. 规则如下: src/ ...

  5. c#系统预定义类型

  6. Orangepi 修改 Debian国内源

    1.导出sources.list 1   cat /etc/apt/sources.list >  sources.list  2.修改sources.list内容为如下: 1234   deb ...

  7. Ubuntu系统---编译opencv程序的几种方式g++、Makefile、Cmake

    Ubuntu系统---编译opencv程序的几种方式g++.Makefile.Cmake 先建立一个工程(一个文件夹),写好xxx.cpp文件,可以是多个: //----------opencv.cp ...

  8. SQL Server CET 通用表表达式 之 精典递归

    SQL2005 Common Table Expressions(CET)即通用表表达式. SQLSERVER CET递归使用案例: 1.普通案例 表结构如下:   ;WITH cet_depart ...

  9. GAN学习指南:从原理入门到制作生成Demo,总共分几步?

    来源:https://www.leiphone.com/news/201701/yZvIqK8VbxoYejLl.html?viewType=weixin 导语:本文介绍下GAN和DCGAN的原理,以 ...

  10. Nginx防盗链模块ngx_http_referer_module

    ngx_http_referer_module⽤用来阻⽌止Referer⾸首部⽆无有效值的请求访问,可防⽌止盗链指令:12.1 valid_referers定义 referer ⾸首部的合法可⽤用值, ...