错误:areq Bad Argument参数'PanelController'不是函数,未定义

时间:2015-01-22 12:16:11

标签: javascript html angularjs

这是我的Html

<body ng-controller="StoreController as store">
   ...........
    <section  ng-controller="PanelController as panel">
        <ul class="nav nav-pills"">
            <li ng-class="{active:panel.isSelected(1)}">
            <a href="#" ng-click="panel.selectTab(1)">Description</a>
            </li>
            <li ng-class="{active:panel.isSelected(2)}">
            <a href="#" ng-click="panel.selectTab(2)">Specification</a>
            </li>
            <li ng-class="{active:panel.isSelected(3)}">
            <a href="#" ng-click="panel.selectTab(1)">Reviews</a>
            </li>
        </ul>
        <div class="panel" ng-show="panel.isSelected(1)" >
          <h4>Description</h4>
          <p>{{product.description}}</p>
        </div>
        <div class="panel" ng-show="panel.isSelected(2)">
          <h4>Specification</h4>
          <p>Enter the product specification here</p>
         </div>
         <div class="panel" ng-show="panel.isSelected(3)">
           <h4>Review</h4>
           <p>Product review goes here.</p>
         </div>
    </section>
   </div>
<body>

这是我的Js文件,我遇到的问题是在添加PanelController之后,但我找不到它的错误

(function(){
    var app= angular.module("store",[]);
    app.controller("StoreController", function(){
       this.products = gems;
    });
    app.controller("PanelController", function(){
        this.tab = 1;
        this.selectTab = function(setTab){
            this.tab = setTab;
        };
        this.isSelected = function(checkedTab){
            return this.tab === checkedTab;
        };
    });
    var gems=[
    {
        name:'Ruby',
        price:1000000,
        description:'It originally .......... ',    
        images:
        {
            thumb:'red.jpg',
            full :'blue.jpg'
        },

        canPurchase:true,
    },
    .......
    ]

})();

当我添加PanelController时出现此错误,任何人都可以帮助我吗? 提前谢谢

1 个答案:

答案 0 :(得分:0)

这个错误几乎总是与事实相关,即

  1. 您的控制器位于某个模块中,该模块不属于 ng-app 中指定的根模块,或
  2. 未加载包含(控制器).js
  3. 我在这里采取了你的片段 - 他们正在按原样工作:

    http://plnkr.co/edit/WUeFelbaMrrRebQZjpWg?p=info

    使用ng-app的唯一扩展如下:

    <!DOCTYPE html>
    <html ng-app="store">
       <head>...</head>
       <body ng-controller="StoreController as store">
       ...