我有一个下拉列表: -
<label>User Code:</label>
<select ng-options="c as c.User for c in userList"
ng-model="selectedUser" id="search3">
</select>
此下拉列表中的数据来自API。我的指令代码: -
scope.getAllPeriodicities = function(){
scope.userList = [];
ApiServices.getAllPeriodicities().then(function (response) {
scope.userList = response.data;
});
}
scope.getAllPeriodicities();
有一个用户代码: - SS1234
。我想在页面加载时选择此用户。我正在考虑使用selected
属性,但不确定如何在获取的数据上使用它。
答案 0 :(得分:1)
scope.getAllPeriodicities = function(){
scope.userList = [];
ApiServices.getAllPeriodicities().then(function (response) {
scope.userList = response.data;
scope.selectedUser = "SS1234";
});
}
scope.getAllPeriodicities();
答案 1 :(得分:1)
使用ng-model
或ng-init
ng-value
<select ng-options="c as c.User for c in userList" ng-model="selectedUser"
id="search3" ng-value={{selectedUser = 'SS1234'}}></select>
//或
<select ng-options="c as c.User for c in userList" ng-model="selectedUser"
id="search3" ng-init="selectedUser = 'SS1234'"></select>
答案 2 :(得分:1)
只需asign,def complexNumberMultiply(self, a, b):
"""
:type a: str
:type b: str
:rtype: str
"""
c,d = a.split('+')
e,f = b.split('+')
d = int(d[:-1])
f = int(f[:-1])
print c,d,e,f
return '%s+%si' % (c * e - d * f, c * f + d * e)
您想要的用户。
scope.selectedUser="SS1234"
答案 3 :(得分:0)
在你的控制器中添加
$scope.selectedUser = 'SS1234';