What is easy way to convert object in array Angular JS?

前端 未结 3 1421
失恋的感觉
失恋的感觉 2021-01-05 07:30

My application was built on Angular JS and has a lot AJAX requests on server. For example, in PHP I format output array like as:

$dialog[$us         


        
3条回答
  •  天涯浪人
    2021-01-05 08:07

    Let's say you have an object like:

    $scope.myObj = {type:"Fiat", model:500, color:"white"};
    

    Then, in your angular Controller you can do something like:

    $scope.array = [];
    angular.forEach($scope.myObj, function(element) {
      $scope.array.push(element);
    });
    

    and then in your HTML

    {{obj}}

    Here is a demo plunker

提交回复
热议问题