I get data from URL in controller but i need it dynamically
d3.json("http://localhost:2016/get_stats_for?brand_name="+$scope.brand,function(data))
i want to get $scope.brand from textBox in the view
how could i do that ?
EDIT 2
Alternatively, you can use ng-change instead.
app.controller('MyController', function($scope, MyService){
$scope.brand = 'D&G'; //initialize value
$scope.onBrandChange = function(){
MyService.getByBrand($scope.brand).then(function(res){
var result = res.data; //here is your JSON
});
});
});
app.service('MyService', function($http){
this.getByBrand = function(brand){
var URL = "http://localhost:2016/get_stats_forbrand_name="+brand;
return $http.get(URL);
};
});
<div ng-controller='MyController'>
<input type='text' ng-change='onBrandChange()' ng-model-options="{debounce: 100}" ng-model='brand'></input>
</div>
You want to track changes to the variable from the scope?
$scope.$watch('brand', function(newValue, oldValue){
//fetch the json file
});
add the following to the ng-model element on the view
ng-model-options="{debounce: 100}"
The update will occur only if element was unchanged for more than 100ms (so in case of fast typing browser won't be throttled by multiple fetch requests)