Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJs-ng选项在ajax调用后不绑定_Javascript_Jquery_Ajax_Angularjs_Ng Options - Fatal编程技术网

Javascript AngularJs-ng选项在ajax调用后不绑定

Javascript AngularJs-ng选项在ajax调用后不绑定,javascript,jquery,ajax,angularjs,ng-options,Javascript,Jquery,Ajax,Angularjs,Ng Options,我尝试在ajax调用后更改ng选项的选定索引,但不会更改 //Html Section... <select id="fooId" ng-model ="foo.formula" ng-options="formulas as name for (formulas, name) in the_formula"></select> //End Html Section... //js file... //get list of formula from se

我尝试在ajax调用后更改ng选项的选定索引,但不会更改

//Html Section...

<select id="fooId" ng-model ="foo.formula"
   ng-options="formulas as name for (formulas, name) in the_formula"></select>

//End Html Section...


//js file...

//get list of formula from server...
TheSource.Get.then(function(response){
    $scope.the_formula = response.the_formula;
});


//do something awesome, then..
//binding data from server...

TheData.Get.then(function(response){
    //binding the data to view...
    //all of the element is binding, except the ng-options part..
    $scope.foo = response; 

    //not working..
    //$scope.formula = response.formulaId //it is return integer ID like (1, 2, 3, etc..)
});

// End js file...
怎么了?如何自动更改ng选项中的选择?

@raveldarat

你好,

在使用select和ng选项时,我也遇到了同样的情况:

你必须做的是-

在从ajax调用和绑定中检索到的数据完成后,设置“foo.formula”的值。 原因-呈现Html时。它绑定select标记中的“foo.formula”。当时没有填充任何项目。一段时间后,从后面(js)填充项目,并且没有为该ng模型触发触发器

经过很多努力,我发现了这个-

示例-

下面是您在js中需要做的事情

   .success(function (data) {  
            $scope.$emit('HideLoading');  
            $scope.departments = data.DepartmentsGetResult;  
            $scope.selectedDepartment = item.DepartmentId;  
这是我的HTML-

<select   
   data-ng-model="selectedDepartment"   
   data-ng-options="dept.DepartmentId as dept.Title for dept in departments" >  
 </select>  

希望这会有所帮助。
让我知道您的担忧。

:)

您有
ng选项=“…在\u公式中”
,然后
$scope.the\u公式=…
,然后
$scope.formula=…
。这些是指同一个变量吗?它应该拼写相同,区分大小写。哎呀,对不起,编辑错误。但它在实际代码中工作。嗨,还是不走运。我想这是因为承诺,但不是。所以这一定是关于我使用的数据。我用我使用的数据更新了问题。希望您能提供帮助。不要将其与-ng model=“foo.formula”绑定。尝试将其与-ng model=“selectedformula”绑定。
<select   
   data-ng-model="selectedDepartment"   
   data-ng-options="dept.DepartmentId as dept.Title for dept in departments" >  
 </select>