2015-11-06 111 views
0

不太确定这是关于什么,但我有一些在Monaca以外的工作很好,一旦在Monaca我得到这个: 错误:[ng:areq]参数'的ListCtrl”不是一个函数,得到了不确定'ListCtrl'不是一个函数,得到了undefined

这里是代码:

<script> 
var app = ons.bootstrap('propertyDeal', ['onsen']); 
app.factory('Property', function() { 

    /** 
    * Constructor, with class name 
    */ 
    function Property(newProperty) { 
     // Public properties, assigned to the instance ('this') 
     this.purchasePrice = newProperty.pprice; 
     this.marketValue = newProperty.mv; 
     this.stampDuty = newProperty.stamp; 
     this.sourcingFee = newProperty.sourcing; 
     this.legaFee = newProperty.legal; 
     this.otherFee = newProperty.other; 
     } 

    /** 
    * Public method, assigned to prototype 
    */ 
    Property.prototype.getPurchasePrice = function() { 
     return this.purchasePrice; 
    }; 

    return { 
     createNew: function(newProperty) { 
      console.log("Alert accomplished"); 
      return new Property(newProperty); 
     } 
    }; 
}); 

app.factory('portfolio', function(Property){ 
    var portfolio = {}; 
    portfolio.list = []; 

    portfolio.add = function(newProperty){ 
     var prop = Property.createNew(newProperty); 
     portfolio.list.push(prop); 
     alert(prop.purchasePrice); 
    }; 

    return portfolio; 
}); 

app.controller('ListCtrl', function(portfolio) { 
    var self = this; 
    self.portfolio = portfolio.list; 
}); 

app.controller('PostCtrl', function(portfolio){ 
    var self = this; 

    self.addProperty = function(newProperty){ 
     portfolio.add(newProperty); 
    }; 
}); 

</script> 

<ons-navigator> 
<ons-page> 
    <div class="container" ng-controller="TopMenuController" ng-init="init('Initial investment','ion-social-usd')"> 
     <div ng-include="url"></div> 
    </div> 

    <div style="text-align: center"> 
     <h2>Initial investment</h2> 

     <ul class="list"> 
       <input type="hidden" ng-model="newProperty.id" placeholder="id"> 
      <li class="list__item"> 
       <input type="text" class="text-input text-input--transparent" style="width:100%; margin-top:4px;" ng-model="newProperty.pprice" placeholder="Purchase price"> 
      </li> 
      <li class="list__item"> 
       <input type="text" class="text-input text-input--transparent" style="width:100%; margin-top:4px;" ng-model="newProperty.mv" placeholder="Market value"> 
      </li> 
      <li class="list__item"> 
       <input type="text" class="text-input text-input--transparent" style="width:100%; margin-top:4px;" ng-model="newProperty.stamp" placeholder="Stamp duty"> 
      </li> 
      <li class="list__item"> 
       <input type="text" class="text-input text-input--transparent" style="width:100%; margin-top:4px;" ng-model="newProperty.sourcing" placeholder="Sourcing fee"> 
      </li> 
      <li class="list__item"> 
       <input type="text" class="text-input text-input--transparent" style="width:100%; margin-top:4px;" ng-model="newProperty.legal" placeholder="Legal fee"> 
      </li> 
      <li class="list__item"> 
       <input type="text" class="text-input text-input--transparent" style="width:100%; margin-top:4px;" ng-model="newProperty.other" placeholder="Other"> 
      </li> 
     </ul> 
    </div> 
    <br /> 
    <div data-ng-controller="ListCtrl as list"> 
     <p ng-repeat="prop in list.portfolio track by $index"> 
      New Object: {{prop.purchasePrice}}: {{prop.legaFee}} </p> 
    </div> 

    <div ng-controller="PostCtrl as post"> 
     <input type="button" ng-click="post.addProperty(newProperty)" value="Create Property"></input> 
     <p>{{newProperty}}</p> 
    </div> 
</ons-page> 
</ons-navigator> 

我不明白什么是错与此知道在捣鼓例如 测试时,该完全相同的代码工作http://jsfiddle.net/XmWUP/129/

谢谢你的帮助

+0

你在哪里定义你的应用程序?没有'var app = angular.module('name',[]);'它是否有空数组?这可能会导致这个错误,如果它的缺失,你还没有定义它。该数组告诉角'创建此模块',否则它会显示'找我这个模块'。另外抱歉,这是一个宠物讨厌的东西,但不需要在代码中将'this'作为'self'来别名。 – ste2425

+0

谢谢ste2425。引导程序在另一个pahe上,我已经添加了它,这与onsen-ui有点不同,但如果我理解的很好,它与模块声明的功能相同。 我知道自我和这个,但是之前编辑了一些代码使得它没有必要并且没有改变它,但正如你所说的,这里不是问题。 – nocrack

回答

0

你的代码看起来很好,除了ng-controller="TopMenuController",这是没有定义。

可能的问题与角版本有关,你的jsfiddle示例使用1.2.6但莫尼卡使用1.4.3Onsen UI 1.3.11

检查此CodePen example

+0

感谢您的回答。 TopMenuController在另一个页面中定义,我只是复制了页面。 – nocrack

+0

我认为这将是因为不同的版本,但我不明白如何改变以及如何使它与这个版本一起工作。 我看不出你的codepen与我的代码有什么不同,除了它运行于1.3.11之外的事实 – nocrack

+0

Onsen UI 1.x基于Angular,一些元素已被弃用/更改/从Angular 1.2添加到1.4,这可能是为什么。 –

相关问题