简体   繁体   English

将选择元素与Angular 1.5绑定

[英]Bind select element with Angular 1.5

I don't know why when I run my page the options are well rendered but when I do a inspect element in Chrome I can see that the value of my options are not well. 我不知道为什么在运行页面时可以很好地呈现选项,但是当我在Chrome中执行检查元素时,我可以看到选项的值并不理想。 It gives me the value="object:8" 它给了我value =“ object:8”

<option label="Teacher" value="object:8">Teacher</option>

If I replicate my code in fiddle , it works well. 如果我将代码复制到小提琴中 ,它将很好地工作。 The value for the first option is value="1" 第一个选项的值为value =“ 1”

This "select" element is in a modal which is in a template page that is called in a ui-view 此“选择”元素处于模态,该模态在ui视图中调用的模板页面中

This is the html 这是HTML

<select 
       x-ng-model="filteredCategory" 
       x-ng-options="category.name for category in categories" >
    <option value="">-- Choose a category --</option>
</select>

This piece of code from controller 这段来自控制器的代码

app.controller('CategoriesController', function ($scope, $stateParams, $uibModal, RegistrationService) {

    RegistrationService.getCategories().then(function(categories){
        $scope.categories = categories;
    });
});

I tested the result of my restful web service with postman chrome 我用邮递员chrome测试了我宁静的Web服务的结果

[
  {
    "id": 1,
    "name": "Teacher"
  },
  {
    "id": 2,
    "name": "Student"
  },
  {
    "id": 3,
    "name": "Coordinator"
  },
]

What is my mistake? 我怎么了

I found this article that explains why angular is parsing my value as object:#. 我发现这篇文章解释了为什么angular将我的值解析为object:#。

I don't know why it doesn't work on my modal in angular but in jsfiddle works well. 我不知道为什么它在我的模态中不起作用,但是在jsfiddle中效果很好。

Hope this help anyone else. 希望这对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM