Angularjs 如何在angular.js中设置函数或从参数中获取值

Angularjs 如何在angular.js中设置函数或从参数中获取值,angularjs,angularjs-scope,Angularjs,Angularjs Scope,我在anguler方面比较新,希望从选择选项中更改一个值,并希望更新特定ID的状态。我已经设置了一些代码,但这不起作用。你能帮助我吗。 获取数据并获取数据,然后设置一个选择框 <select ng-model="newStatus" ng-change="changeNewStatus(data.id, data.message_status)"> <option value="1" ng-selected="data.message

我在anguler方面比较新,希望从选择选项中更改一个值,并希望更新特定ID的状态。我已经设置了一些代码,但这不起作用。你能帮助我吗。 获取数据并获取数据,然后设置一个选择框

<select ng-model="newStatus" ng-change="changeNewStatus(data.id, data.message_status)">
                      <option value="1" ng-selected="data.message_status == 1">New</option>
                      <option value="2" ng-selected="data.message_status == 2">Closed</option>
                    </select>
这是我的全部代码

app.filter('startFrom', function() {
return function(input, start) {
    if(input) {
        start = +start; //parse to int
        return input.slice(start);
    }
    return [];
}
}))

}))

您可以使用ng options指令:
部分:
挑选
{{selected}}
js:
var app=角度模块(“测试”,[]);
app.controller(“TestController”、[“$scope”、函数($scope){
$scope.items=[{
id:1,
标签:“阿拉贝尔”
}, {
id:2,
标签:“布拉贝尔”
}];
}]);
例子
http://codepen.io/anon/pen/MaRMPz
您可以使用ng选项指令:
部分:
挑选
{{selected}}
js:
var app=角度模块(“测试”,[]);
app.controller(“TestController”、[“$scope”、函数($scope){
$scope.items=[{
id:1,
标签:“阿拉贝尔”
}, {
id:2,
标签:“布拉贝尔”
}];
}]);
例子
http://codepen.io/anon/pen/MaRMPz

数据从哪里来?您在哪里使用newStatus模型值?数据是通过数据参数中的ajax来的newStatus模型是在选择选项中声明的您当前在html中获得的
selectedResult
是什么?目前这里没有任何内容,但我需要更改消息ID和状态值。之后,如果您想使用ajax更新数据库中的消息状态,php@alexjolig数据来自何处?您在何处使用newStatus模型值?数据来自数据参数中的ajax newStatus模型在选择选项中声明您当前在html中获得的
selectedResult
是什么,但我想更改消息ID和状态值。之后,要使用ajax更新数据库中的消息状态,php@AlexJolighow要从该代码中获取更改值,请选择New Closed,您可以添加ng change=“getSelectedValue()”,并且在控制器中,ng模型将为您提供所选值$scope.getSelectedValue=function(){console.log(“selected value is”,selected);}如何从此代码中获取更改值选择New Closed您可以添加ng change=“getSelectedValue()”,并且在控制器中,ng模型将为您提供所选值$scope.getSelectedValue=function(){console.log(“选定值为”,选定);}
app.filter('startFrom', function() {
return function(input, start) {
    if(input) {
        start = +start; //parse to int
        return input.slice(start);
    }
    return [];
}
app.controller('MessageFetchGrid', function ($scope, $http, $timeout) {
$http.get('api/v1/loadMessage.php').success(function(data){
    $scope.list = data;
    $scope.currentPage = 1; //current page
    $scope.entryLimit = 25; //max no of items to display in a page
    $scope.filteredItems = $scope.list.length; //Initially for no filter  
    $scope.totalItems = $scope.list.length;
});
$scope.setPage = function(pageNo) {
    $scope.currentPage = pageNo;
};
$scope.filter = function() {
    $timeout(function() { 
        $scope.filteredItems = $scope.filtered.length;
    }, 10);
};
$scope.sort_by = function(predicate) {
    $scope.predicate = predicate;
    $scope.reverse = !$scope.reverse;
};  
$scope.changeNewStatus = function(msgId, msgStatus){
        $scope.selectedResult = "msg-id="+msgId+" status= "+msgStatus;
}   
    you can use ng-options directive :
partial:
<div ng-app="test">
  <div ng-controller="TestController">
    <select ng-options="item as item.label for item in items track by item.id" ng-model="selected">
      <option value="">Select</optipn>
    </select>
    <span>{{selected}}</span>
  </div>
</div>

js:
var app = angular.module("test", []);
app.controller("TestController", ["$scope", function($scope) {
  $scope.items = [{
    id: 1,
    label: 'aLabel'
  }, {
    id: 2,
    label: 'bLabel'
  }];
}]);
    example 
    http://codepen.io/anon/pen/MaRMPz