我正在使用Angularjs开发一个网站,我是初学者。 所以我有一个组合框。选择一个选项后,它会调用一个方法,并应在Scope变量中加载值并进行更新。 这是我的代码。
if(array[i].text.indexOf('hello') > -1){
//Rest of your code
}
和HTML部分
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope, $http) {
$scope.castVals = {};
$http.get("http://localhost:8083/project/php/get_recipies.php")
.success(function (response) {
$scope.recipies = response.records;
$scope.selectedItem = null;
});
$scope.selectedItemChanged = function (val) {
$http.get("http://localhost:8083/project/php/get_cast_param.php?v="+val)
.success(function (response) {
$scope.castVals = response;
});
};
});
由于 阿什拉夫
答案 0 :(得分:0)
您不需要将所选值传递给selectedItemChange方法,因为从范围变量获取它在控制器上更安全。
<select id="soflow" ng-model="selectedItem" ng-change="selectedItemChanged()">
<option ng-repeat="rec in recipies" value="{{rec.Rezept_Nr}}">{{rec.Rezept_Bez}}</option>
</select>
//控制器
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope, $http) {
$scope.castVals = {};
$scope.selectedItem;
$http.get("http://localhost:8083/project/php/get_recipies.php")
.success(function (response) {
$scope.recipies = response.records;
$scope.selectedItem = null;
});
$scope.selectedItemChanged = function () {
$http.get("http://localhost:8083/project/php/get_cast_param.php?v="+ $scope.selectedItem)
.success(function (response) {
$scope.castVals = response;
});
};
});