您好我是angularjs的新手,並試圖在提交按鈕的onclick過程中調用一個函數。
我的HTML頁面:
<div class="form-group">
<a href="#" ng-click="showGraph = !showGraph" class="btn btn-primary btn-lg" ng-disabled="!model.selectedRole">SUBMIT</a>
</div>
</form>
</div>
</div><! end of previous div -->
<div class="col-sm-6"> <!-- new div -->
<div class="panel panel-primary">
<div class="panel-heading" style="background-color:#F8F8FF; text-decoration:none; color:black"><b>Chart</b></div>
<div class="panel-body" ng-change="HeadCount()" ng-show="showGraph">
<plot class="barchart" height="300" width="400" yaxis-label-text="'No. of Students'"
xaxis-label-text="'standards'" ymin="0" ymax="100" xodomain="ordinals" >
<bar-group type="'grouped'" arrangement="'vertical'" style="opacity:100;">
<bars data="available_students" position-function="'/0'" value-function="'/1'"
fill="'red'"></bars>
<bars data="maximum_students" position-function="'/0'" value-function="'/1'" fill="'blue'" ></bars>
</bar-group>
</plot>
</div>
</div>
</div> <!-- end of new div -->
這裏我使用ng-click="showGraph = !showGraph"
打電話給我showGraph在我的控制器。
我控制器頁
$scope.showGraph = false;
$scope.HeadCount = function(){
var json_response = {
"data": [
{
"standard": "Ist",
"max_students": 20,
"available_students": 8
},
{
"standard": "IInd",
"max_students": 15,
"available_students": 10
},
{
"standard": "IIIrd",
"max_students": 50,
"available_students": 22
}
]
}
$scope.available_students = [ ['Ist', 8,], ['IInd', 10], ['IIIrd', 22]];
$scope.maximum_students = [['Ist', 15], ['IInd',15], ['IIIrd', 50]];
$scope.ordinals = ['Ist', 'IInd', 'IIIrd'];
console.log($scope.ordinals.length);
$cookieStore.put('xaxisLength',$scope.ordinals.length);
}
我需要通過單擊提交按鈕後,調用來自控制器HeadCount()
函數來顯示圖表。
但我得到錯誤,當我點擊提交按鈕表單正在刷新。
Error: [$compile:ctreq] Controller 'ngModel', required by directive 'ngShow', can't be found!
任何人都可以請幫助我,我需要進行更改。
ngChange僅用於不帶div的表單元素。 –