5

私のアプリケーションでは、データを取得するために http サービスを呼び出しており、angular-ui ブートストラップの typeahead ディレクティブ (ui-bootstrap-tpls-0.6.0.min.js) を使用しています。コントローラーに言及するフォームを持つパーシャルがあり、ng-repeat 内にパーシャルが含まれています。この 2 番目の部分には先行入力があります。

メイン フォームの部分:

<form
    id="myform" 
    name="myform"
    onsubmit="javascript: return false"
    enctype="application/json"
    ng-controller="EducationCollegeCtrl">
    // doing other stuff
    ...

    <div ng-if="model.hasData">
        <div ng-repeat="college in model.academicRecords" ng-form="collegeForm">
            <div ng-include="'resources/appc/modules/main/education/components/collegetype.all.html'"></div>
        </div>
    </div>
    // other stuff going on here

collegetype.all.html:

....
        <label for="institution">Institution name:</label>
        <div>
              <input type="text" ng-model="college.organizationName"  typeahead="item.name for item in matchingInstitutions($viewValue)>
        </div>
        ....

EducationCollegeCtrl.js:

angular.module('theApp',['ui.bootstrap']).controller('EducationCollegeCtrl', function ($scope, $http) {
   ...
    $scope.matchingInstitutions = function(partialName) {
        return $http.get('lookup/institutions?name=' + partialName ).then(function(response){
            return response.data.institutions;
        }); 
    };

   ...

サービスが呼び出され、ドロップダウンが機関の名前とともに正しく表示されます。しかし、ブラウザー コンソールでは、ドロップダウンのすべてのエントリに対して以下のエラーが表示されます。

console.log:

Error: No controller: ngModel
at Error (<anonymous>)
at getControllers (/resources/lib/angular/1.1.5/angular.js:4899:39)
at nodeLinkFn (/resources/lib/angular/1.1.5/angular.js:5040:55)
at compositeLinkFn (/resources/lib/angular/1.1.5/angular.js:4626:37)
at nodeLinkFn (/resources/lib/angular/1.1.5/angular.js:5033:40)
at compositeLinkFn (/resources/lib/angular/1.1.5/angular.js:4626:37)
at publicLinkFn (/resources/lib/angular/1.1.5/angular.js:4531:46)
at ngRepeatAction (/resources/lib/angular/1.1.5/angular.js:15638:33)
at Object.$watchCollectionAction (/resources/lib/angular/1.1.5/angular.js:8867:29)
at Object.applyFunction [as fn] (<anonymous>:778:50) <typeahead-match index="$index" match="match" query="query" template-url="templateUrl" class="ng-isolate-scope ng-scope"> angular.js:6422

エラーについての私の理解は、ディレクティブの「必須」属性が欠落しており、それがangularが不満を言っていることですが、部分的にわかるように、ng-model属性が定義されており、コントローラーも指定されていますメインフォーム部分で。ここで何が欠けていますか?

編集: URL の無関係な部分を削除しました。

4

1 に答える 1

0

ng-includechild を作成します。$scopeこれは、プロトタイプとしてその parent を継承し$scopeます。つまり、親の変数をng-model="college.organizationName"参照するのではなく、それをシャドウします。collegeそして、新しい変数にはプロパティcollegeがありません。organizationName最も簡単な方法は、 「自分自身を繰り返さない」ルールをすでに回避しng-includeているため、おそらく使用しないことです。ng-repeat

于 2014-01-24T11:19:05.507 に答える