角度UI选择不显示初始值

时间:2018-08-08 16:55:42

标签: angularjs angular-ui-select

我有一个包含“合作伙伴”字段的表单。用户应该能够通过查找替代合作伙伴并选择它来设置或更改合作伙伴,因此我在该字段中使用ui-select。范围中定义了变量 formNodeValue ,该变量包含带有ID和NAME的“伙伴”对象。我的问题是,尽管 formNodeValue 设置为:

"I am script in page B running on window.location: http://localhost:3000/turbobugs/a"

这就是我使用ui-select的方式:

<?php   
session_start();
$reqrole = "user";
$admin = "admin";
$superuser = "superuser";

if(!isset($_SESSION['user']))
       {
           header("Location:login.html");  
       }
       if(!isset($_SESSION['role']))
       {
           header("Location:login.html");  
       }
       if ($_SESSION['role'] != $reqrole and $_SESSION['role'] != $superuser and $_SESSION['role'] != $admin)
       {
           header("Location:login.html");  
       }
?>

formNodeValue 实际上是一个获取/设置函数。在不带参数的情况下调用它会返回一个对象。当使用参数调用它时,它将作为设置器使用,并且不返回任何值。

1 个答案:

答案 0 :(得分:0)

作为Ui-Select常见问题解答

https://github.com/angular-ui/ui-select/wiki/FAQs

ng-model无法在$ scope上使用简单变量

You cannot write:    
<ui-select ng-model="item"> <!-- Wrong -->
  [...]
</ui-select>

You need to write:    
<ui-select ng-model="item.selected"> <!-- Correct -->
  [...]
</ui-select>

尝试像这样设置formNodeValue

{
  selected: {
    id: 124,
    name: 'Partner name'
  }
}