Hello.
I am using Metronic theme html demo 53 and AngularJS (1.6.9) for my project.
I am trying to set select2 as an option along with AngularJS but to no avail.
If I set
<select ng-change="selectedRow()" ng-model="selectedName" ng-options="x.Name for x in myData" class="form-select" data-control="select2" data-allow-clear="true" data-placeholder="Select an option" id="kt_ecommerce_edit_order_billing_country_man" name="billing_order_country">
</select>
app.controller("articalCtrl", function($scope, $http) {
$http.get("products.php").then(function (response) {
$scope.myData = response.data.records;
});
$scope.selectedRow = function() {
alert("Selected");
}
});
<select ng-change="selectedRow()" ng-model="selectedName" ng-options="x.Name for x in myData" class="form-select" data-placeholder="Select an option" id="kt_ecommerce_edit_order_billing_country_man" name="billing_order_country">
</select>
data-control=select2 data-allow-clear=true
Hi Alex,
Could you please try to follow these steps:
1. Remove the data-control="select2" and data-allow-clear="true" attributes from the < select> element.
2. Metronic should already have the Select2 library included. In your AngularJS controller, initialize the Select2 plugin after the data is loaded using the $http service. You can do this in the callback function of the $http.get method.
Example:
app.controller("articalCtrl", function($scope, $http) {
$http.get("products.php").then(function(response) {
$scope.myData = response.data.records;
// Initialize Select2 after data is loaded
$("#kt_ecommerce_edit_order_billing_country_man").select2();
});
$scope.selectedRow = function() {
alert("Selected");
};
});
< select ng-change="selectedRow()" ng-model="selectedName" ng-options="x.Name for x in myData" class="form-select" data-placeholder="Select an option" name="billing_order_country">
</select>