2017-05-31 46 views
0

我是新來的角JS和嘗試添加選項來選擇採用了棱角分明,但面臨的問題:NG選項問題

以下是代碼

/* 
 
* To change this license header, choose License Headers in Project Properties. 
 
* To change this template file, choose Tools | Templates 
 
* and open the template in the editor. 
 
*/ 
 

 
var mymodule = angular.module("firstform",['$scope']); 
 

 

 
mymodule.controller("selectgroupcontroller",['$scope', function($scope){ 
 
     
 
     // $scope.optgrps = selectGroupFactory.optgrps; 
 
     $scope.optgrps = [ 
 
           {name : 'First', value : '1', group : '1-3'}, 
 
           {name : 'Second', value : '2', group : '1-3'}, 
 
           {name : 'Third', value : '3', group : '1-3'}, 
 
           {name : 'Fourth', value : '4', group : '4-6'}, 
 
           {name : 'Fifth', value : '5', group : '4-6'}, 
 
           {name : 'Sixth', value : '6', group : '4-6'}, 
 
           
 
           
 
          ] ; 
 
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div class="row" ng-app="firstform"> 
 
    <div class="col-sm-12"> 
 
    <form name="selecttest" novalidate="" ng-controller="selectgroupcontroller"> 
 
     <div class="form-group"> 
 
     <div class="control-label text-center col-sm-2"> 
 
      <label for="selectgrp">Select Value: </label> 
 
     </div> 
 
     <div class="col-sm-10"> 
 
      <select class="form-control" ng-model="selectedVal" id="selectgrp" ng-options="val.value as (val.name+val.value) group by val.group for val in optgrps"> 
 

 
      </select> 
 
     </div> 
 
     </div> 
 
    </form> 
 

 

 
    </div> 
 
</div>

代碼很容易爲選擇選項和打印添加組。 但它沒有給出任何錯誤,也沒有給出任何輸出。

+0

你的代碼似乎不錯..究竟會發生什麼? –

+0

我不確定檢查片段,輸出沒有顯示出來。 – Avdhut

回答

1

提示錯誤Error: [$injector:modulerr]刪除$範圍模塊注入

var mymodule = angular.module("firstform",[]); 

/* 
 
* To change this license header, choose License Headers in Project Properties. 
 
* To change this template file, choose Tools | Templates 
 
* and open the template in the editor. 
 
*/ 
 

 
var mymodule = angular.module("firstform",[]); 
 

 

 
mymodule.controller("selectgroupcontroller",['$scope', function($scope){ 
 
     
 
     // $scope.optgrps = selectGroupFactory.optgrps; 
 
     $scope.optgrps = [ 
 
           {name : 'First', value : '1', group : '1-3'}, 
 
           {name : 'Second', value : '2', group : '1-3'}, 
 
           {name : 'Third', value : '3', group : '1-3'}, 
 
           {name : 'Fourth', value : '4', group : '4-6'}, 
 
           {name : 'Fifth', value : '5', group : '4-6'}, 
 
           {name : 'Sixth', value : '6', group : '4-6'}, 
 
           
 
           
 
          ] ; 
 
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div class="row" ng-app="firstform"> 
 
    <div class="col-sm-12"> 
 
    <form name="selecttest" novalidate="" ng-controller="selectgroupcontroller"> 
 
     <div class="form-group"> 
 
     <div class="control-label text-center col-sm-2"> 
 
      <label for="selectgrp">Select Value: </label> 
 
     </div> 
 
     <div class="col-sm-10"> 
 
      <select class="form-control" ng-model="selectedVal" id="selectgrp" ng-options="val.value as (val.name+val.value) group by val.group for val in optgrps"> 
 

 
      </select> 
 
     </div> 
 
     </div> 
 
    </form> 
 

 

 
    </div> 
 
</div>

+0

但是網上的很多例子顯示了$ scope的注入,那麼爲什麼它會在上面的情況下創建一個錯誤。 – Avdhut