[英]Nested Controller with ng-click in angular js
I have an Item controller and User controller can apply to it.So I have created Apply controller to do this but the problem is that I have Item view page from there I have to pass item id to my Apply controller's apply method. 我有一个Item控制器,并且User控制器可以对其应用。因此,我创建了Apply控制器来执行此操作,但是问题是我从那里有了Item视图页面,所以我必须将item id传递给我的Apply控制器的apply方法。
My Page 我的页面
<div class="container_12" ng-controller="ItemCtrl" ng-init="profile()">
<div class="gallery" >
<ul class="unstyled">
<h1>{{item.name}}</h1>
<br>
<ul>
<li>About: {{item.description}}</li>
</ul>
</ul>
<br>
<div ng-controller="ApplyCtrl">
<button ng-click="apply(item._id)">Show Interest</button>
</div>
</div>
</div>
So I want nested ng-controller
because I want the item id to pass but for this my console shows error. 所以我想要嵌套的ng-controller
因为我希望传递项目ID,但为此我的控制台显示错误。
Error: [ng:areq] http://errors.angularjs.org/1.4.8/ng/areq?p0=ApplyCtrl&p1=not%20a%20function%2C%20got%20undefined
at Error (native)
at http://localhost:8080/vendor/angular/angular.min.js:6:416
at qb (http://localhost:8080/vendor/angular/angular.min.js:22:131)
at Qa (http://localhost:8080/vendor/angular/angular.min.js:22:218)
at http://localhost:8080/vendor/angular/angular.min.js:80:210
at w (http://localhost:8080/vendor/angular/angular.min.js:60:177)
at D (http://localhost:8080/vendor/angular/angular.min.js:61:30)
at g (http://localhost:8080/vendor/angular/angular.min.js:55:105)
at g (http://localhost:8080/vendor/angular/angular.min.js:55:122)
at D (http://localhost:8080/vendor/angular/angular.min.js:62:134)(anonymous function) @ angular.js:12520(anonymous function) @ angular.js:9292r.$apply @ angular.js:16157(anonymous function) @ angular.js:1679e @ angular.js:4523c @ angular.js:1677yc @ angular.js:1697Zd @ angular.js:1591(anonymous function) @ angular.js:29013c @ jquery.js:3p.fireWith @ jquery.js:3x.extend.ready @ jquery.js:3q @ jquery.js:3
Is there any way I can achieve this? 有什么办法可以实现?
Short Term - Based on the console error, it appears ApplyCtrl isn't even recognized by your AngularJS - I would confirm the javascript file that instantiates your ApplyCtrl is being loaded. 短期-根据控制台错误,您的AngularJS甚至无法识别ApplyCtrl-我会确认正在加载实例化ApplyCtrl的javascript文件。
Long Term - What you are essentially trying to achieve is a nested view - I highly recommend looking at UI Router , which will handle exactly what you are trying to achieve. 长期-本质上您想要实现的是一个嵌套视图-我强烈建议您查看UI Router ,它可以准确地处理您要实现的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.