簡體   English   中英

用ng-click在angular js中嵌套控制器

[英]Nested Controller with ng-click in angular js

我有一個Item控制器,並且User控制器可以對其應用。因此,我創建了Apply控制器來執行此操作,但是問題是我從那里有了Item視圖頁面,所以我必須將item id傳遞給我的Apply控制器的apply方法。

我的頁面

<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>

所以我想要嵌套的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 

有什么辦法可以實現?

短期-根據控制台錯誤,您的AngularJS甚至無法識別ApplyCtrl-我會確認正在加載實例化ApplyCtrl的javascript文件。

長期-本質上您想要實現的是一個嵌套視圖-我強烈建議您查看UI Router ,它可以准確地處理您要實現的目標。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM