how to create syncfusion dropdownlist in angularjs - angularjs

I am using syncfusion dropdownlist. I want to create a dropdownlist for blood group in my form. How can I do that in angularjs?
<input type="text" ej-dropdownlist e-datasource="BloodGroup_List" e-value="Name" ng-model="employee.bloodgroup">
In my controller I have written,
$scope.bloodgroup = [{ "Id": "1", "Name": "O+" },
{ "Id": "2", "Name": "O-" },
{ "Id": "3", "Name": "A+" },
{ "Id": "4", "Name": "A-" },
{ "Id": "5", "Name": "B+" },
{ "Id": "6", "Name": "B-" },
{ "Id": "7", "Name": "AB+" },
{ "Id": "8", "Name": "AB-" }];
$scope.BloodGroup_List = $scope.bloodgroup;
The above code is not working, where am I wrong?

You need to map the data source to the corresponding attributes in "fields" property.
<input type="text" id="bloodgroup" ej-dropdownlist e-datasource="BloodGroup_List" e-fields-text="Name" e-fields-value="Name" e-fields-id="Id" e-value="value">
In the script, inject 'ejAngular' and specify your values as shown below
angular.module('DropCtrl', ['ejangular'])
.controller('DropDownCtrl', function ($scope) {
$scope.bloodgroup = [{ "Id": "1", "Name": "O+" },
{ "Id": "2", "Name": "O-" },
{ "Id": "3", "Name": "A+" },
{ "Id": "4", "Name": "A-" },
{ "Id": "5", "Name": "B+" },
{ "Id": "6", "Name": "B-" },
{ "Id": "7", "Name": "AB+" },
{ "Id": "8", "Name": "AB-" }];
$scope.BloodGroup_List = $scope.bloodgroup;
$scope.value = "AB-";
});
This will work for you.

Try this..
<select ng-model="selectedItem">
<option ng-repeat="bloodgroupvalue in bloodgroup" value="{{bloodgroupvalue.Id}}">{{bloodgroupvalue.Name}}</option>
</select>
or
<select ng-model="selectedItem" ng-options="bloodgroupvalue.Name for bloodgroupvalue in bloodgroup">
</select>

You need to use e-fields-text="Name" to show text on in the dropdown then it will bind the value to that ng-model
HTML
<input id="test" type="text" ej-dropdownlist e-datasource="BloodGroup_List" e-fields-text="Name"
e-fields-value="Name" ng-model="employee.bloodgroup" e-change="selectedBloodGroup"/>
CODE
$scope.selectedBloodGroup = function(args) {
$scope.employee.bloodgroup = args.value;
$scope.$apply();
};
Working Plunkr

Related

AngularJS multiple Scope needed for Autocomplete

I have an array structure like this.
[
{
"id": "1",
"name": "John",
"city": "NY"
},
{
"id": "2",
"name": "Gerold",
"city": "LA"
},
{
"id": "3",
"name": "Stuart",
"city": "Boston"
}
]
I need $scope like below for my autocomplete search.
$scope.name=["john","Gerold","Stuart"];
$scope.city=["NY","LA","Boston"];
can anyone help to get this using angularjs controller.
Thanks in Advance.!
Use MAP
$scope.users = [
{
"id": "1",
"name": "John",
"city": "NY"
},
{
"id": "2",
"name": "Gerold",
"city": "LA"
},
{
"id": "3",
"name": "Stuart",
"city": "Boston"
}
];
$scope.cities = $scope.users.map(function(obj){
return obj.city;
});
console.log($scope.cities);
You can also create a helper function that would do that for you and you don't have to define a map per function that you want, and you do it in just one run (hence just a bit faster)
Sample here ;)
var myArray = [
{
"id": "1",
"name": "John",
"city": "NY"
},
{
"id": "2",
"name": "Gerold",
"city": "LA"
},
{
"id": "3",
"name": "Stuart",
"city": "Boston"
}
]
function toScope(scopedPropertieNames, array) {
scopedPropertieNames.forEach(function(propertyName) {
if (! $scope[propertyName]) {
$scope[propertyName] = []
}
});
array.forEach(function (objecInArray) {
scopedPropertieNames.forEach(function(propertyName) {
$scope[propertyName].push(objecInArray[propertyName])
})
});
}
toScope(['name', 'city'], myArray);
console.log($scope) //{name: Array[3], city: Array[3]}
You can use MAP..
$scope.YourBigArray = [{
"id": "1",
"name": "John",
"city": "NY"
}, {
"id": "2",
"name": "Gerold",
"city": "LA"
}, {
"id": "3",
"name": "Stuart",
"city": "Boston"
}];
$scope.names = $scope.YourBigArray.map(function(object) {
return object.name;
});
$scope.cities = $scope.YourBigArray.map(function(object) {
return object.city;
});
You can do a filter to use unique things in array of names and cities..
function filterForDuplicate(things) {
return things.filter(function(item, pos) {
return things.indexOf(item) === pos;
});
}

Show Category hierarchy using AngularJS

I wanna show a category hierarchy data and I use angularJS with ng-repeat and ng-if.Here's to my demo file:
<div ng-app="" ng-controller="DanhMucController">
<ul>
<li ng-repeat="danhmuc in DanhMucList" ng-if="danhmuc.depended==0">{{danhmuc.name}}
<ul>
<li ng-repeat="danhmuc in DanhMucList" ng-if="danhmuc.depended==2">
{{danhmuc.name}}
<ul ng-repeat="danhmuc in DanhMucList" ng-if="danhmuc.depended==4">
<li>{{danhmuc.name}}</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
controller:
<script>
function DanhMucController($scope, $http) {
var url = "category.txt";
$http.get(url).success(function(response) {
$scope.DanhMucList = response;
});
}
</script>
this file category data :
[{
"id": "1",
"name": "Parent1",
"depended": "0"
}, {
"id": "2",
"name": "Parent2",
"depended": "0"
}, {
"id": "3",
"name": "Parent3",
"depended": "0"
}, {
"id": "4",
"name": "ChildA",
"depended": "1"
}, {
"id": "5",
"name": "ChildB",
"depended": "2"
}, {
"id": "6",
"name": "ChildC",
"depended": "3"
}, {
"id": "7",
"name": "grandChildA",
"depended": "4"
}, {
"id": "8",
"name": "grandChildB",
"depended": "5"
}, {
"id": "9",
"name": "grandChildC",
"depended": "6"
}, {
"id": "10",
"name": "grandChildD",
"depended": "5"
}, {
"id": "11",
"name": "grandChildE",
"depended": "6"
}, {
"id": "12",
"name": "grandChildF",
"depended": "3"
}]
category Image
But I can not define the id of parent so it dont show data which I need .It must display:
-Parent 1 contain ChildA.
-Parent 2 contain ChildB.
-Parent 3 contain ChildC.
Everyone can suggest me a solution for my issues. Thanks all
you can do something like this here.
I would suggest though you arrange your data better instead of looping over the same data 3 times.

group subdocuments - angularjs

i have object value in JSON, within which it contains array.i am trying to group the subdocument but does not work. my plunk
The below is my controller code.
Controller
app.controller('MainCtrl', function($scope) {
$scope.list = {
"_id": "56c4758af801160e00d176e0",
"orderfood": [
{
"_id": "569d84f04834c10e003dff36",
"qty": "1",
"confirm": "placed",
"price": 125,
"name": "Paneer Tikka"
},
{
"_id": "569d869fff1fe20e00f8ba9b",
"qty": "1",
"confirm": "placed",
"price": 85,
"name": "Falooda"
},
{
"_id": "569d869fff1fe20e00f8ba9b",
"qty": "1",
"confirm": "placed",
"price": 85,
"name": "Falooda"
}
],
"title": "Status",
"created": "2016-02-17T13:28:42.226Z"
}
});
The below is my HTML code
HTML
<p ng-repeat="(key,value) in list.orderfood | groupBy:'name'">
{{key}}
</p>
my plunk
Dont know what you want your ouput to be but you need to do this with a custom function:
<div ng-app ng-controller="Main">
<div ng-repeat="list in itemsToFilter() | filter:filterNames">
<b>{{list.name}}</b>
<li ng-repeat="item in itemsToFilter() | filter: {name: list.name}">NAME: {{item.name}}- PRICE: {{item.price}}, etc...</li>
</div>
</div>
Then in your controller:
function Main($scope) {
$scope.list = {
"_id": "56c4758af801160e00d176e0",
"orderfood": [
{
"_id": "569d84f04834c10e003dff36",
"qty": "1",
"confirm": "placed",
"price": 125,
"name": "Paneer Tikka"
},
{
"_id": "569d869fff1fe20e00f8ba9b",
"qty": "1",
"confirm": "placed",
"price": 85,
"name": "Falooda"
},
{
"_id": "569d869fff1fe20e00f8ba9b",
"qty": "1",
"confirm": "placed",
"price": 85,
"name": "Falooda"
}
],
"title": "Status",
"created": "2016-02-17T13:28:42.226Z"
}
var indexedTeams = [];
$scope.itemsToFilter = function() {
indexedTeams = [];
return $scope.list.orderfood;
}
$scope.filterNames = function(item) {
var nameIsNew = indexedTeams.indexOf(item.name) == -1;
if (nameIsNew) {
indexedTeams.push(item.name);
}
return nameIsNew;
}
}
here is a link...js-fiddle exmple: http://jsfiddle.net/L6cQN/305/

ngTagsInput does not seem to be supporting objects inside a JSON string

My CakePHP application generates a JSON output of all my categories as shown below:
{
"categories": [
{
"Category": {
"id": "7",
"name": "Elektronics"
}
},
{
"Category": {
"id": "8",
"name": "Gym"
}
},
{
"Category": {
"id": "4",
"name": "Nightlife"
}
},
{
"Category": {
"id": "6",
"name": "Shopping "
}
},
{
"Category": {
"id": "2",
"name": "Sport"
}
}
]
}
How can I use this data with the ngTagsInput plugin? I tried it like this but it always shows an error. It seems like it cannot handle multiple objects.
<label class="item item-input item-stacked-label">
<span class="input-label">Categories</span>
<tags-input ng-model="tags" display-property="Category.name" placeholder="New Category">
<auto-complete source="loadTags($query)"></auto-complete>
</tags-input>
</label>
Error:
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: tag in tagList.items track by track(tag), Duplicate key: undefined, Duplicate value: {"Category":{"id":"7","name":"Electronics"}}
http://errors.angularjs.org/1.4.3/ngRepeat/dupes?p0=tag%20in%20tagList.item…2%3A%7B%22id%22%3A%225%22%2C%22name%22%3A%22Essen%20und%20Trinken%22%7D%7D
at ionic.bundle.js:8900
at ngRepeatAction (ionic.bundle.js:35974)
at Object.$watchCollectionAction [as fn] (ionic.bundle.js:24382)
at Scope.$digest (ionic.bundle.js:24515)
at Scope.$apply (ionic.bundle.js:24783)
at done (ionic.bundle.js:19196)
at completeRequest (ionic.bundle.js:19368)
at XMLHttpRequest.requestLoaded (ionic.bundle.js:19309)
UPDATE
You could create a function that converts your object in something that tags-input can understand.
var object = {
"categories": [
{
"Category": {
"id": "7",
"name": "Elektronics"
}
},
{
"Category": {
"id": "8",
"name": "Gym"
}
},
{
"Category": {
"id": "4",
"name": "Nightlife"
}
},
{
"Category": {
"id": "6",
"name": "Shopping "
}
},
{
"Category": {
"id": "2",
"name": "Sport"
}
}
]
};
var categories = [];
for(var i = 0; i < object.categories.length; i++){
var category = object.categories[i].Category;
var categoryToPush = {
id: category.id,
name: category.name
};
categories.push(categoryToPush);
}
categories will contain:
[{
"id": "7",
"name": "Elektronics"
}, {
"id": "8",
"name": "Gym"
}, {
"id": "4",
"name": "Nightlife"
}, {
"id": "6",
"name": "Shopping "
}, {
"id": "2",
"name": "Sport"
}]
So then you can use it in the directive writing:
<tags-input ng-model="tags" display-property="name">
<auto-complete source="loadTags($query)"></auto-complete>
</tags-input>
OLD ANSWER
Add a key-property value:
<tags-input ng-model="tags" display-property="Category.name" key-property="Category.id" placeholder="New Category">
<auto-complete source="loadTags($query)"></auto-complete>
</tags-input>
Similar issue.

How can I convert object data to an array for use with bs-typeahead in AngularJS?

My data looks like:
[
{
"_id": "531dbf8b9b9fc50000a8d611",
"active": true,
"client": {
"_id": "531dbf8b9b9fc50000a8d60e",
"name": "TR"
},
"company_id": "531dbf8b9b9fc50000a8d60c",
"createdOn": "2014-03-10T13:35:07.313Z",
"description": "Gentle Action Application Pads",
"dimensions": {
"weight": 22.4
},
"lot": [
],
"meta": {
"category": "Face",
"msrp": 7.75
},
"sku": "11002",
"unit_of_measure": "each",
"updatedOn": "2014-03-10T13:35:07.314Z"
},
{
"_id": "531dbf8b9b9fc50000a8d612",
"active": true,
"client": {
"_id": "531dbf8b9b9fc50000a8d60e",
"name": "TR"
},
"company_id": "531dbf8b9b9fc50000a8d60c",
"createdOn": "2014-03-10T13:35:07.317Z",
"description": "Skin Renewal System - Enriched (CA)",
"dimensions": {
"weight": 22.4
},
"lot": [
],
"meta": {
"category": "Face",
"msrp": 321.6
},
"sku": "11700CA",
"unit_of_measure": "each",
"updatedOn": "2014-03-10T13:35:07.318Z"
}
]
In my view, I have:
<input type="text" ng-model="receivingSku" placeholder="Locations loaded via $http" typeahead="sku for sku in getSku($viewValue) | filter:$viewValue" typeahead-on-select="selectedSku()" class="form-control">
I need the sku field for each item to be in the typeahead. How can I accomplish this?
Presently, I get an error:
Error: matches is undefined
You can loop over your original array and create an array of just SKU's:
var skus = origArray.map(function(e) {
return e.sku;
});
The new array can be used for typeahead.
PS - I'm not very familiar with typeahead. If typeahead is capable of peeking into objects, you don't need to do this.

Resources