Can someone help me with the following HTML code?
<div ng-controller="select">
<select ng-options="n for n in names"
ng-model="selected.item"
ng-change="change()">
</select>
</div>
<div ng-controller="graph">
<input type="text" ng-model="mySelected.item">
<canvas id="line" class="chart chart-line" chart-labels="gs" chart-data="ser">
</canvas>
</div>
I need the "change()" method in ng-option to trigger the "graph" controller when an option is selected. Essentially, when the option changes, I want the graph to update. Is there a way to achieve this? Please provide guidance.
Below is the code for my controllers:
app.controller('graph', ['$scope', '$http', 'myService', function($scope,$http, myService) {
$scope.mySelected = myService.selected;
console.log($scope.mySelected);
//$http.get('/myapp/stocklist/'+ $scope.mySelected).
$http.get('/myapp/stocklist/AMZN').
success(function(data) {
gs = [];
ser = [];
for( var i=0; i<data.length; i++ ) {
gs.push(data[i].name);
ser.push(data[i].high);
}
$scope.gs=gs;
$scope.ser=[];
$scope.ser.push(ser);
});
}]);
app.controller('select', ['$scope', '$http', 'myService', function($scope,$http, myService) {
$scope.selected = myService.selected;
$http.get('/myapp/stocknames').
success(function(data) {
$scope.names=data;
console.log($scope.names);
});
}]);