2017-05-31 74 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