1

I got ng-repeat to read array:

<div layout="row" layout-align="start end">
        <md-input-container flex="20">
            <label>Product Name *</label>
            <md-select required ng-model="review.productName">
                <md-option ng-repeat="pn in productName_array" value="{{pn}}">{{pn}}</md-option>
            </md-select>
        </md-input-container>
    </div>

And this is the angular code,

self.productName_array  = ["abe","abe1","abe2","abe3"];

The resulting array can be read. But it can't be read when I change the initiation to this angular code.

This is the controller:

self.productName_array  = request.getProductName();

This is the request script:

obj.getProductName = function (){
    return $http.get(api_base + 'getProductName').then(function (results) { return results.data;});
};

This is the API script:

private function getProductName(){
    $this->product->findName();
}

This is the query:

public function findName(){
    if($this->get_request_method() != "GET") $this->response('',406);
    $query="SELECT name FROM product p ORDER BY p.id DESC";
    $this->show_response($this->db->get_list_name($query));
}

The result from the angular code is like this:

[["Xiaomi Pocophone F1"],["Samsung Galaxy S9+"],["Samsung Galaxy Note9"],["Iphone XR"],["Iphone XS"],["XIAOMI MI A1 RAM 4\/32GB"],["Iphone XS Max"],["VIVO Y71"],["SAMSUNG GALAXY J2 PRIME"],["SAMSUNG GALAXY J7 PRIME"],["HomeIPHONEIPHONE 6S+"],["HONOR 9 LITE"],["EVERCOSS AT7H"],["Blackberry Aurora"]]
3
  • Possible duplicate of How do I return the response from an asynchronous call? Commented Sep 17, 2018 at 20:34
  • It bears repeating: There's no such thing as a "JSON array"; it's just a normal array, no need to mention JSON. Commented Sep 17, 2018 at 20:36
  • you should consider changing your structure to something like [{productName:"Xiaomi Pocophone F1"}, {productName:"Samsung Galaxy S9+"}, ...etc] Commented Sep 18, 2018 at 14:27

2 Answers 2

1

Although it doesnt really need to be done, if yyou need it as a json use:

var newJson = JSON.stringify(ArrayName);
Sign up to request clarification or add additional context in comments.

Comments

0

Looking at your dynamic result, it appears that your controller is assigning an array containing an array. To access the values you can use

  <md-option ng-repeat="pn in productName_array[0]" value="{{pn}}">{{pn}}</md-option>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.