Javascript 无法在角度控制器的更改事件中获取下拉列表的选定值

Javascript 无法在角度控制器的更改事件中获取下拉列表的选定值,javascript,jquery,html,angularjs,ajax,Javascript,Jquery,Html,Angularjs,Ajax,我尝试了我找到的所有方法,但它不起作用,我只是简单地尝试以angular js的方式在其更改事件上选择下拉菜单选项,以便将其传递到ajax并从数据库中获取数据。我的项目中有angular.min.js 1.4.8版本的cdn 我将代码复制/粘贴到plunker中,它工作正常,但在浏览器中运行项目时,它不工作。下面是我的JS和html代码片段 JS代码 $scope.inputs = [{ id : 1, name : 'option1', value : 'option1

我尝试了我找到的所有方法,但它不起作用,我只是简单地尝试以angular js的方式在其更改事件上选择下拉菜单选项,以便将其传递到ajax并从数据库中获取数据。我的项目中有angular.min.js 1.4.8版本的cdn

我将代码复制/粘贴到plunker中,它工作正常,但在浏览器中运行项目时,它不工作。下面是我的JS和html代码片段

JS代码

$scope.inputs = [{
    id : 1,
    name : 'option1',
    value : 'option1',
    inputType : 'tag',
    valueOperator : "option1Operator",
    operatorType : 'operatorType1'
    }, {
    id : 2,
    name : 'option2',
    value : 'option2',
    inputType : 'text',
    valueOperator : "option2Operator",
    operatorType : 'operatorType1'
    }];
$scope.inputSelectedChange = function(){
        $scope.$watch('inputSelected',function( val ){
               $http({
                  method: 'GET',
                  url: '<<URL>>',
                  responseType: 'json',
                  params:{inputName: "prdSeqId"}
                }).then(function successCallback(response) {
                     //something
}, function errorCallback(response) {
                    // called asynchronously if an error occurs
                    // or server returns response with an error status.
                  });
});
<select ng-model="inputSelected" 
        ng-options="input as input.name for input in inputs" 
        ng-change="inputSelectedChange()" required>
    <option value="">Select Input</option>
</select>
$scope.inputs=[{
id:1,
名称:“选项1”,
值:'option1',
inputType:'标记',
valueOperator:“option1Operator”,
运算符类型:“运算符类型1”
}, {
id:2,
名称:“选项2”,
值:'option2',
inputType:'文本',
valueOperator:“option2Operator”,
运算符类型:“运算符类型1”
}];
$scope.inputSelectedChange=函数(){
$scope.$watch('inputSelected',函数(val){
$http({
方法:“GET”,
url:“”,
responseType:'json',
参数:{inputName:“prdSeqId”}
}).then(函数成功回调(响应){
//某物
},函数errorCallback(响应){
//发生错误时异步调用
//或服务器返回带有错误状态的响应。
});
});
HTML代码

$scope.inputs = [{
    id : 1,
    name : 'option1',
    value : 'option1',
    inputType : 'tag',
    valueOperator : "option1Operator",
    operatorType : 'operatorType1'
    }, {
    id : 2,
    name : 'option2',
    value : 'option2',
    inputType : 'text',
    valueOperator : "option2Operator",
    operatorType : 'operatorType1'
    }];
$scope.inputSelectedChange = function(){
        $scope.$watch('inputSelected',function( val ){
               $http({
                  method: 'GET',
                  url: '<<URL>>',
                  responseType: 'json',
                  params:{inputName: "prdSeqId"}
                }).then(function successCallback(response) {
                     //something
}, function errorCallback(response) {
                    // called asynchronously if an error occurs
                    // or server returns response with an error status.
                  });
});
<select ng-model="inputSelected" 
        ng-options="input as input.name for input in inputs" 
        ng-change="inputSelectedChange()" required>
    <option value="">Select Input</option>
</select>

选择输入

尝试更改如下功能: 并获得价值

$scope.inputSelectedChange = function(){
  console.log($scope.inputSelected)
  //do other stuff here
}

您可以从
ng model

var myApp=angular.module('myApp',[]);
//指令('myDirective',function(){});
//工厂('myService',function(){});
函数MyCtrl($scope){
$scope.inputs=[{
id:1,
名称:“选项1”,
值:'option1',
inputType:'标记',
valueOperator:“option1Operator”,
运算符类型:“运算符类型1”
}, {
id:2,
名称:“选项2”,
值:'option2',
inputType:'文本',
valueOperator:“option2Operator”,
运算符类型:“运算符类型1”
}];
$scope.inputSelectedChange=函数(){
console.log($scope.inputSelected)
}
}

选择输入
//html
选择输入
//控制器
$scope.inputSelectedChange=函数(值){
console.log(值)
};

您不必使用$scope。$注意您的ng更改功能,因为ng模型值将在您的controllerPlease read中提供-总结是,这不是解决志愿者问题的理想方法,可能会对获得答案产生反作用。请不要将此添加到您的问题中。n-模型值未定义无论是否使用$scope.$watch,我都尝试了这两种方法。谢谢您在console中是否有任何错误?请检查下面的答案,并尝试重新创建相同的代码@RohitMishraI在传入ng change name(而不是inputSelected),这是一个愚蠢的错误。。非常感谢您的解决方案。:)