加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs controller控制器注入对象顺序

发布时间:2020-12-17 09:58:58 所属栏目:安全 来源:网络整理
导读:angularjs在controller中注入server的时候,需要注意注入服务的顺序,否则会出现server没有自己定义的功能方法的奇怪现象。 错误案例: //选择支付类型.state('selectCashType',{url: '/detailsPayIncom/selectCashType',templateUrl: 'detailsPayIncom/sele

angularjs在controller中注入server的时候,需要注意注入服务的顺序,否则会出现server没有自己定义的功能方法的奇怪现象。

错误案例:

//选择支付类型
.state('selectCashType',{
	url: '/detailsPayIncom/selectCashType',templateUrl: 'detailsPayIncom/selectCashType.html',controller: ["$scope","$state",function ($state,$scope) {
		$scope.jumpTo = function(){
			$state.go("getCashByZhifubao");
		}
	}]
})

$scope 和 $state 分别是数组的第0个 和 第1个值,那么最后的controller函数的参数必须要要与之一一对应。

上述例子中,函数中的$http实际上是前面数组第1个值$state的实例。

解决办法:

//选择支付类型
.state('selectCashType',function ($scope,$state) {
		$scope.jumpTo = function(){
			$state.go("getCashByZhifubao");
		}
	}]
})

将数组前面注入的server字符串 与 最后一个函数的参数顺序一一对应。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读