0

I want to have a selected inside of my modal that depends on $http result.

This is my template modal

var templateModal = "<div class='modal-body'>" +
"<span>Orderer List </span>" +
    "<select ng-model='editable.orderer' ng-init='editable.orderer=\"{{editable.orderer_id}}\"'>" +
       "<option ng-repeat='x in ordererNames' value='{{x.ID}}'>{{x.post_title}}</option>" +
    "</select> <br/>" +
"</div>";

This is my script to open my modal

$scope.edit = function(data) {
        var modalInstance = $uibModal.open({
            template:templateModal,
            controller: managementModal,
            resolve: {
                items: function() {
                    return data;
                }
            }
        });
}

Management Modal controller

var managementModal = function($scope, $http, $uibModalInstance, items){
    $scope.names = items;
    $scope.editable = items;
    $http({
        method: "POST",
        url: Ajax_call.ajaxurl,
        params: {
            action: "orderer_names"
        }
    }).then(function(names){
        $scope.ordererNames = names.data;
        console.log($scope.ordererNames[0].ID)
    });

    $http({
        method: "POST",
        url: Ajax_call.ajaxurl,
        params: {
            action: "creator_names"
        }
    }).then(function(names){
        $scope.creatorNames = names.data;
    });

    $scope.cancel = function(){
        $uibModalInstance.dismiss(true);
    };
    $scope.update = function(){
        $uibModalInstance.close($scope.editable);
    };
};

This is what Ive tried so far Ive put an ng-init it doesnt selected if I put this but when I change the {{editable.orderer_id}} into a number it will be selected. I dont know why?

"<select ng-model='editable.orderer' ng-init='editable.orderer=\"{{editable.orderer_id}}\"'>" +

Also Ive tried ng-selected too

"<option ng-selected='editable.orderer_id == x.ID' ng-repeat='x in ordererNames' value='{{x.ID}}'>{{x.post_title}}</option>"

But still no luck

already read this answers

ng-selected ng-init

EDITED

the JSON

[{
    "ID": 403,
    "post_title": "Kelly Johnson"
}, {
    "ID": 337,
    "post_title": "Staff"
}, {
    "ID": 287,
    "post_title": "Marie Cury"
}, {
    "ID": 278,
    "post_title": "Matugas"
},{
    "ID": 102,
    "post_title": "Antony Edison"
}]

0 Answers0