在Angularjs中将数据从视图传递到控制器
我从控制器中的URL获取数据,但我需要动态地获取数据在Angularjs中将数据从视图传递到控制器,angularjs,binding,Angularjs,Binding,我从控制器中的URL获取数据,但我需要动态地获取数据 d3.json("http://localhost:2016/get_stats_for?brand_name="+$scope.brand,function(data)) 我想从视图中的文本框中获取$scope.brand 我怎么能这么做 编辑2 或者,您可以使用ng change app.controller('MyController',函数($scope,MyService){ $scope.brand='D&G';//初始化值
d3.json("http://localhost:2016/get_stats_for?brand_name="+$scope.brand,function(data))
我想从视图中的文本框中获取$scope.brand
我怎么能这么做 编辑2
或者,您可以使用ng change
app.controller('MyController',函数($scope,MyService){
$scope.brand='D&G';//初始化值
$scope.onBrandChange=function(){
getByBrand($scope.brand)。然后(函数(res){
var result=res.data;//这是您的JSON
});
});
});
app.service('MyService',函数($http){
this.getByBrand=函数(品牌){
变量URL=”http://localhost:2016/get_stats_forbrand_name=“+品牌;
返回$http.get(URL);
};
});代码>
我有一个带有条件和值的url。这个值需要从view.html中的文本框中设置