gpt4 book ai didi

angularjs - ng-options 显示空白的选定选项,即使 ng-model 已定义

转载 作者:行者123 更新时间:2023-12-04 09:25:35 31 4
gpt4 key购买 nike

我创建了一个 plunkr 来强调这个问题,也许是因为 ng-repeat 的来源是一个函数,我不确定,但到目前为止,我已经尝试了一切来解决这个问题,但无法管理。

笨蛋:
http://plnkr.co/edit/qQFsRM?p=preview

HTML

<html>

<head>
<script data-require="angular.js@1.2.0-rc1" data-semver="1.2.0-rc1" src="http://code.angularjs.org/1.2.0rc1/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>

<body ng-app='myApp' ng-controller='mainCtrl'>
<ng-include src="'menu.html'">
</ng-include>

</html>

脚本
var app = angular.module('myApp', []);

app.controller('mainCtrl', function($scope, $httpBackend){
$scope.model = {};
$scope.model.myJobs = {};
$scope.refreshJobs = function(){

}
});

app.controller('menuCtrl', function($scope){

$scope.model.locations = function(){
var loc = [];
loc[1] = 'Dublin';
loc[2] = 'Stockholm';
loc[3] = 'New Jersy';
$scope.model.selectedLocationDef = loc.indexOf('Dublin');
return loc;
}
$scope.model.selectedLocation = $scope.model.selectedLocationDef;

$scope.$watch('model.selectedLocation', function(location){
$scope.refreshJobs(location);
});

});

最佳答案

如果使用数组作为模型,则模型是字符串而不是数字。所以你需要将数字转换为字符串。你试一试

$scope.model.selectedLocation = '1';

关于angularjs - ng-options 显示空白的选定选项,即使 ng-model 已定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18335797/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com