gpt4 book ai didi

angularjs - 如何使用 ng-click on ng-option(或其他赋值方式)

转载 作者:行者123 更新时间:2023-12-03 20:14:26 24 4
gpt4 key购买 nike

如何使用 ng-options。

$scope.fieldTable = [
{
filed:"text",
title:"Global"
},
{
field: "relatedentity",
title: "Entity"
},
{
field:"title",
title:"Title"
},
{
field: "content",
title: "Content"
}
]

I want to build a which use the title as displayed and when select something, popout a alert window which display the according field.最初的选择是
{ 
filed:"text",
title:"Global"
}

任何人都可以帮忙吗?

最佳答案

var app = angular.module('stack', []);

app.controller('MainCtrl', function($scope) {
$scope.fieldTable = [{
field: "text",
title: "Global"
}, {
field: "relatedentity",
title: "Entity"
}, {
field: "title",
title: "Title"
}, {
field: "content",
title: "Content"
}];

$scope.selected = $scope.fieldTable[0];

$scope.hasChanged = function() {
alert($scope.selected.field);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="stack" ng-controller="MainCtrl">
<select ng-options="item.title for item in fieldTable" ng-model="selected" ng-change="hasChanged()">
</select>
</body>

关于angularjs - 如何使用 ng-click on ng-option(或其他赋值方式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29519805/

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