angularjs 外部调用controller中的方法
angular.element(document.querySelector('[ng-controller=mainCtrl]')).scope().viewGo('tab.VIPPay_Success',{})
<!DOCTYPE html>
<html ng-app="myApp" id="myApp">
<head>
<meta name="viewport" content="width=device-width" />
<title>Test</title>
<script src="~/Content/Js/Plugins/AngularJS/angular.min.js"></script>
</head>
<body ng-controller="myController">
{{msg}}
<a href="javascript:;" id="lbtnTest">调用</a>
</body>
</html>
<script>
var ngApp = angular.module('myApp', []);
ngApp.controller('myController', function ($scope, $http) {
$scope.msg = '你好,Angular!';
$scope.getData = function () {
return 'qubernet';
}
});
onload = function () {
document.getElementById('lbtnTest').onclick = function () {
//通过controller来获取Angular应用
var appElement = document.querySelector('[ng-controller=myController]');
//获取$scope变量
var $scope = angular.element(appElement).scope();
//调用msg变量,并改变msg的值
$scope.msg = '123456';
//上一行改变了msg的值,如果想同步到Angular控制器中,则需要调用$apply()方法即可
$scope.$apply();
//调用控制器中的getData()方法
console.log($scope.getData());
}
}
</script>
http://www.jb51.net/article/89939.htm
angularjs 外部调用controller中的方法的更多相关文章
- Spring的Aspect切面类不能拦截Controller中的方法
根本原因在于<aop:aspectj-autoproxy />这句话是在spring的配置文件内,还是在springmvc的配置文件内.如果是在spring的配置文件内,则@Control ...
- ASP.NET MVC4在View中调用当前Controller中的方法
调用当前Controller中的方法 @{ ((HomeController)ViewContext.Controller).Method1(); } 调用静态方法 @{ SomeClass.Meth ...
- Spring AOP无法拦截Controller中的方法
想使用AOP Annotation配置Spring MVC的Controller进行拦截, 发现无法拦截Controller的方法, 却可以拦截Service层的方法. 一开始: Spring的配置文 ...
- spring MVC controller中的方法跳转到另外controller中的某个method的方法
1. 需求背景 需求:spring MVC框架controller间跳转,需重定向.有几种情况:不带参数跳转,带参数拼接url形式跳转,带参数不拼接参数跳转,页面也能显示. 本来以为挺简单的一 ...
- spingAOP在springMVC中的使用(我用在拦截controller中的方法。主要用于登录控制)
首先截取了网上的一张配置execution的图片 我在项目中关于aop的配置:如果拦截controller的方法,需要在spring-mvc.xml文件中加入(如果在spring.xml中加入则无法拦 ...
- 反射找Controller中的方法
/// <summary> /// 根据接口编码APICode,调用相应的webapi方法,注意返回值是json字符串 /// </summary> /// <param ...
- SpringMVC controller中业务方法的参数、返回值
业务方法的参数 业务方法的参数类型.参数个数是任意的,根据需要使用. 常见的参数类型: HttpServletRequest.HttpServletResponse.HttpSession 获取 ...
- [.NET WebAPI系列03] WebAPI Controller 中标准CRUD方法
[因] WebAPI的Controller中,一般都是下面四种方法: 对应于数据操作是我们通常所说的CRUD. C对应post,R对应Get,U对应Put,D对应Delete. 直接模仿VS 2012 ...
- Spring拦截器中通过request获取到该请求对应Controller中的method对象
背景:项目使用Spring 3.1.0.RELEASE,从dao到Controller层全部是基于注解配置.我的需求是想在自定义的Spring拦截器中通过request获取到该请求对应于Control ...
随机推荐
- [工作日志] 2018-11-21 主要: 改bug 自测 :校验图片后缀名
正则表达式 用以下方式去校验图片的后缀 String reg = ".+(.JPEG|.jpeg|.JPG|.jpg)$";String imgp= "Redocn_20 ...
- MySQL笔记(1)
数据库和 SQL 概念 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,它的产生距今已有六十多年.随着信息技术和市场的发展,数据库变得无处不在:它在电子商务.银行系统 等众多领域 ...
- 转 linux常用查看硬件设备信息命令
转载自:http://blog.chinaunix.net/uid-26782198-id-3242120.html 系统 # uname -a # 查看内核/操作系统/C ...
- php获取真实ip地址(转)
REMOTE_ADDR只能获取访问者本地连接中设置的IP,如中南民族大学校园网中自己设置的10.X.XXX.XXX系列IP,而这个函数获取的是局域网网关出口的IP地址, 如果访问者使用代理服务器,将不 ...
- sqlplus/rman登录报权限错误ORA-01031/ORA-04005/0RA-00554
安装Weblogic误操作对Oracle用户属组进行了修改 --本地sqlplus登录报错权限问题??? [oracle@enmo admin]$ sqlplus / as sysdba SQL*Pl ...
- 【leetcode】121-Best Time to Buy and Sell Stock
problem 121. Best Time to Buy and Sell Stock code class Solution { public: int maxProfit(vector<i ...
- Gym102040 .Asia Dhaka Regional Contest(寒假自训第9场)
B .Counting Inversion 题意:给定L,R,求这个区间的逆序对数之和.(L,R<1e15) 思路:一看这个范围就知道是数位DP. 只是维护的东西稍微多一点,需要记录后面的各种数 ...
- HDU 1159:Common Subsequence(LCS模板)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- easyui的select使用
这是一个小demo,其他相关功能查看easyuiAPI,需要注意的是valueField: 'id', textField: 'name'中id指json的key,name指json的值,id和nam ...
- Go Example--函数多返回值
package main import "fmt" func main() { a,b := vals() fmt.Println(a) fmt.Println(b) } //函数 ...