0

これが何についてなのかよくわかりませんが、Monaca の外で問題なく動作するものがありました。Monaca に入ると、次のようになります: Error: [ng:areq] Argument 'ListCtrl' is not a function, got 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/などのフィドルでテストしたときにまったく同じコードが機能していることを知っているため、これの何が問題なのかわかりません。

ご協力ありがとうございました

4

1 に答える 1

0

ng-controller="TopMenuController"定義されていないを除いて、コードは問題ないように見えます。

おそらく問題はAngularバージョンに関連しています.jsfiddleの例では使用しています1.2.6が、Monacaでは.1.4.3Onsen UI 1.3.11

このCodePen の例を確認してください。

于 2015-11-06T10:55:12.407 に答える