控制器,带状态

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. 1249: 人见人爱A^B

    题目描述 求A^B的最后三位数表示的整数. 说明:A^B的含义是“A的B次方”  输入 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果 ...

  2. Pose Estimation

    Human Pose Estimation for Real-World Crowded Scenarios https://arxiv.org/pdf/1907.06922.pdf CrowdPos ...

  3. 计算广告(5)----query意图识别

    目录: 一.简介: 1.用户意图识别概念 2.用户意图识别难点 3.用户意图识别分类 4.意图识别方法: (1)基于规则 (2)基于穷举 (3)基于分类模型 二.意图识别具体做法: 1.数据集 2.数 ...

  4. 关键字final 修饰类、方法、属性、参数类型

    笔记: /** 关键字final(最终的) 标记的类不能被继承, 提高安全性,提高程序的可读性 * 1.final 修饰类,这个类就不能被继承: 如:String类.StringBuffer类.Sys ...

  5. 一个简单易上手的短信服务Spring Boot Starter

    前言 短信服务在用户注册.登录.找回密码等相关操作中,可以让用户使用更加便捷,越来越多的公司都采用短信验证的方式让用户进行操作,从而提高用户的实用性. Spring Boot Starter 由于 S ...

  6. webdriver对各种浏览器的支持

    1.Firefox WebDriver实现了FireFoxDriver,无需用户下载FireFoxDriver. 优点:FireFoxDriver对页面的自动化测试支持得比较好,很直观地模拟页面的操作 ...

  7. JQuery 实践---创建元素包装集

    1. 利用选择器,选择将被JQuery包装的元素 标识和选择DOM元素.JQuery采用我们已经知道的CSS语法并且扩展了一些.为了利用JQuery来选择元素,请把选择器包装在$()中. 基本CSS选 ...

  8. Educational Codeforces Round 74 (Rated for Div. 2)【A,B,C【贪心】,D【正难则反的思想】】

    A. Prime Subtractiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inpu ...

  9. 原生JS实现图片上传并预览功能

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. sql时间加减

    /时间转成年月日时分秒select date_format(now(),'%Y%m%d%H%i%S')//时间转成年月日select date_format(now(),'%Y%m%d')//去年此时 ...