There was a final problem when the project finished. How to avoid filtering when page loads first time.
For example : Opening page with TV checked ? (ng-checked="true") Other amenities is false. If the visitor lifts the tv checkin, the filter is renewed.
My project : fiddle
angular.module('hotelApp', [])
.controller('ContentControler', function ($scope, $timeout) {
var mapOptions = {
zoom: 2,
center: new google.maps.LatLng(40.0000, -98.0000),
mapTypeId: google.maps.MapTypeId.TERRAIN
}
$scope.location_name = "";
$scope.names = [{
prop_Name: 'Location 1',
lat: 43.7000,
long: -79.4000,
amenities: '3'
}, {
prop_Name: 'Location 2',
lat: 40.6700,
long: -73.9400,
amenities: '2'
}, {
prop_Name: 'Location 3',
lat: 41.8819,
long: -87.6278,
amenities: '4'
}, {
prop_Name: 'Location 4',
lat: 34.0500,
long: -118.2500,
amenities: '1, 2'
}, {
prop_Name: 'Location 5',
lat: 36.0800,
long: -115.1522,
amenities: '2, 3'
}];
$scope.map = new google.maps.Map(document.getElementById('map'), mapOptions);
$scope.markers = [];
var infoWindow = new google.maps.InfoWindow();
var createMarker = function (info) {
var marker = new google.maps.Marker({
map: $scope.map,
position: new google.maps.LatLng(info.lat, info.long),
title: info.prop_Name
});
marker.content = '<div class="infoWindowContent"><ul>' + '<li>' + info.prop_Desc + '</li>' + '<li>' + info.prop_Addr + '</li>' + '<li>' + info.prop_Price + '</li>' + '<li>' + info.prop_Dist + '</li>' + '</ul></div>';
google.maps.event.addListener(marker, 'click', function () {
infoWindow.setContent('<h2>' + marker.title + '</h2>' + marker.content);
infoWindow.open($scope.map, marker);
});
$scope.markers.push(marker);
}
for (i = 0; i < $scope.names.length; i++) {
createMarker($scope.names[i]);
}
$scope.openInfoWindow = function (e, selectedMarker) {
e.preventDefault();
google.maps.event.trigger(selectedMarker, 'click');
}
//PROBLEM FILTER HERE
$scope.am_en = function()
{
x = $(".hosting_amenities input:checkbox:checked").map(function(){return $(this).val();}).get();
$scope.ot_Filter = function (location) {
var shouldBeShown = true;
for (var i = 0; i < x.length; i++) {
if (location.amenities.indexOf(x[i]) === -1) {
shouldBeShown = false;
break;
}
}
return shouldBeShown;
};
}
$scope.$watch('nas',
function (newValue, oldValue) {
for (jdx in $scope.markers) {
$scope.markers[jdx].setMap(null);
}
$scope.markers = [];
for (idx in $scope.nas) {
createMarker($scope.nas[idx]);
}
}, true);
});
#map {
height: 220px;
width: 400px;
}
.infoWindowContent {
font-size: 14px !important;
border-top: 1px solid #ccc;
padding-top: 10px;
}
h2 {
margin-bottom: 0;
margin-top: 0;
}
#total_items
{
margin:0px auto;
padding:0px;
text-align:center;
color:#0B173B;
margin-top:50px;
border:2px dashed #013ADF;
font-size:20px;
width:200px;
height:50px;
line-height:50px;
font-weight:bold;
}
#amount
{
color:#DF7401;
font-size:18px;
font-weight:bold;
}
#slider-range
{
margin:0px auto;
padding:0px;
text-align:center;
width:500px;
}
<link href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=&sensor=false&extension=.js"></script>
<div ng-app="hotelApp" ng-controller="ContentControler">
<div id="map"></div>
<div id="class" ng-repeat="marker in markers"></div>
<ul>
<li ng-repeat="x in nas = (names | filter:ot_Filter)">{{ x.prop_Name }}</li>
</ul>
<div class="hosting_amenities">
<h3>Filter:</h3>
<input type="checkbox" name="more_filter[]" value="1" ng-checked="false">WIFI
<input type="checkbox" name="more_filter[]" value="2" ng-checked="true">TV
<input type="checkbox" name="more_filter[]" value="3" ng-checked="false">Cable TV
<input type="checkbox" name="more_filter[]" value="4" ng-checked="false">Klima
<button ng-click="am_en();">Submit</button>
</div>
Currently, you only change the filter once you press the button Submit. However, I recommend you to remove that and place the function ot_Filter outside of the function triggered when you click it. This will make the initial filtering when you load the page possible.
As the next step, I would use ng-model instead of ng-checked:
<input type="checkbox" name="more_filter[]" value="1" ng-model="ot_Checkboxes['wifi']">WIFI
<input type="checkbox" name="more_filter[]" value="2" ng-model="ot_Checkboxes['tv']">TV
<input type="checkbox" name="more_filter[]" value="3" ng-model="ot_Checkboxes['cableTV']">Cable TV
<input type="checkbox" name="more_filter[]" value="4" ng-model="ot_Checkboxes['klima']">Klima
The properties would be initialized in your javascript:
$scope.ot_Checkboxes = {
'wifi': false,
'tv': true,
'cableTV': false,
'klima': false
};
With these changes your code will update your locations automatically. This is a good practice and you can keep a good control of your elements. You will find more information about how to set this properly in this answer
In order for you to see how it looks like, I modified your fiddle here
Related
I have a AngularJS application in which I have a table as You can see in the image below,
as you can see the last column contains a delete and and a edit button for every row. How can I highlight row when the corresponding delete button is pressed?
Here is my code: https://plnkr.co/edit/ZNzgVO59eWJSVMH7?preview
var myApp = angular.module('myApp', []);
myApp.constant('Employees',
[{ Name: "Ishan", Code: 1, Is_Intern: "Yes", DateOfJoining: "01/02/2022", Skills: "VB, DOT.NET, Angular", Status: "Working" },
{ Name: "Ashwin", Code: 2, Is_Intern: "No", DateOfJoining: "21/03/2021", Skills: "VB, Ruby, Angular", Status: "Inactive" },
{ Name: "Shailesh", Code: 3, Is_Intern: "Yes", DateOfJoining: "27/04/2021", Skills: "VB, Python, Angular", Status: "Working" },
{ Name: "Pawan", Code: 4, Is_Intern: "No", DateOfJoining: "14/01/2022", Skills: "VB, Sapphire, Angular", Status: "Inactive" }]);
myApp.component('employeeDetail', {
bindings: {
Name: '<',
Code: '<',
Is_Intern: '<',
DateOfJoining: '<',
Skills: '<',
},
controller: 'empCtrl',
});
myApp.controller('empCtrl', function empCtrl($scope, Employees) {
$scope.EmployeeDetails = Employees;
$scope.Name = Employees.Name;
$scope.Code = Employees.Code;
$scope.Is_Intern = Employees.Is_Intern;
$scope.DateOfJoining = Employees.DateOfJoining;
$scope.Skills = Employees.Skills;
$scope.Status = Employees.Status;
$scope.add = function () {
$scope.EmployeeDetails.push({
Name: $scope.Name,
Code: $scope.Code,
Is_Intern: $scope.Is_Intern,
DateOfJoining: $scope.DateOfJoining,
Skills: $scope.Skills,
Status: $scope.Status,
});
$scope.id = '';
$scope.Code = '';
$scope.Is_Intern = '';
$scope.DateOfJoining = '';
$scope.Skills = '';
$scope.Status = '';
};
function select(Name) {
for (let i = 0; i < $scope.EmployeeDetails.length; i++) {
if ($scope.EmployeeDetails[i].Name == Name) {
return i;
}
}
return -1;
};
$scope.edit = function (Name) {
let index = select(Name);
let emp = $scope.EmployeeDetails[index];
$scope.Name = emp.Name;
$scope.Code = emp.Code;
$scope.Is_Intern = emp.Is_Intern;
$scope.DateOfJoining = emp.DateOfJoining;
$scope.Skills = emp.Skills;
$scope.Status = emp.Status;
}
$scope.save = function () {
let index = select($scope.Name);
$scope.EmployeeDetails[index].Name = $scope.Name;
$scope.EmployeeDetails[index].Code = $scope.Code;
$scope.EmployeeDetails[index].Is_Intern = $scope.Is_Intern;
$scope.EmployeeDetails[index].DateOfJoining = $scope.DateOfJoining;
$scope.EmployeeDetails[index].Skills = $scope.Skills;
$scope.EmployeeDetails[index].Status = $scope.Status;
$scope.Name = '';
$scope.Code = '';
$scope.Is_Intern = '';
$scope.DateOfJoining = '';
$scope.Skills = '';
$scope.Status = '';
}
$scope.delete = function (emp) {
if (confirm("Are You Sure You want to delete this record ?")) {
$scope.EmployeeDetails.splice(emp, 1)
alert("Deleted")
}
}
$scope.selectedRow = null;
$scope.setClickedRow = function (index) {
$scope.selectedRow = index;
}
});
table {
border-collapse: collapse;
font-family: Arial;
}
td {
border: 1px solid black;
padding: 5px;
}
th {
border: 1px solid black;
padding: 5px;
text-align: center;
}
label,
input {
display: block;
}
label {
margin-bottom: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<body ng-app="myApp" ng-controller="empCtrl">
<table>
<thead>
<th colspan="8">Names of Employees</th>
</thead>
<tbody>
<tr>
<th>Name</th>
<th>Code</th>
<th>Is_Intern</th>
<th>Skills</th>
<th>Status</th>
<th>DateOfJoining</th>
<th colspan="2" style="text-align: center;">Action</th>
</tr>
<tr ng-repeat="emp in EmployeeDetails">
<td>{{emp.Name}}</td>
<td>{{emp.Code}}</td>
<td>{{emp.Is_Intern}}</td>
<td>{{emp.Skills}}</td>
<td>{{emp.Status}}</td>
<td>{{emp.DateOfJoining}}</td>
<td><button ng-click="edit(emp.Name)">Edit</button></td>
<td><button ng-click="delete($index)">Delete</button></td>
</tr>
</tbody>
<label>
Name
<input ng-model="Name" type="text" />
</label>
<label>
Code
<input ng-model="Code" type="number" />
</label>
<label>
Is_Intern
<input ng-model="Is_Intern" type="text" />
</label>
<label>
Skills
<input ng-model="Skills" type="text" />
</label>
<label>
Status
<input ng-model="Status" type="text" />
</label>
<label>
Date Of Joining
<input ng-model="DateOfJoining" type="text" />
</label>
<label>
<button ng-click="add()">Add</button>
</label>
<button ng-click="save()">Update</button><br><br>
</table>
<br>
</body>
This can be achieved by using ng-class in angular js.
Logic.
On delete button click set some flag on the row to indicate that the row is active I used an isActive class.
Then use a ng-class condition, ng-class="{'highlight': emp.isActive == true}".
Since you are making use of a JavaScript confirm method, you have to use a setTimeout function to trigger the confirm dialog. Or else the changes will not be visible in the DOM.
Since you have used setTimeout, you have to use $scope.$apply() to get your changes reflected in the UI.
Working Fiddle.
var myApp = angular.module('myApp', []);
myApp.constant('Employees',
[{ Name: "Ishan", Code: 1, Is_Intern: "Yes", DateOfJoining: "01/02/2022", Skills: "VB, DOT.NET, Angular", Status: "Working" },
{ Name: "Ashwin", Code: 2, Is_Intern: "No", DateOfJoining: "21/03/2021", Skills: "VB, Ruby, Angular", Status: "Inactive" },
{ Name: "Shailesh", Code: 3, Is_Intern: "Yes", DateOfJoining: "27/04/2021", Skills: "VB, Python, Angular", Status: "Working" },
{ Name: "Pawan", Code: 4, Is_Intern: "No", DateOfJoining: "14/01/2022", Skills: "VB, Sapphire, Angular", Status: "Inactive" }]);
myApp.component('employeeDetail', {
bindings: {
Name: '<',
Code: '<',
Is_Intern: '<',
DateOfJoining: '<',
Skills: '<',
},
controller: 'empCtrl',
});
myApp.controller('empCtrl', function empCtrl($scope, Employees) {
$scope.EmployeeDetails = Employees;
$scope.Name = Employees.Name;
$scope.Code = Employees.Code;
$scope.Is_Intern = Employees.Is_Intern;
$scope.DateOfJoining = Employees.DateOfJoining;
$scope.Skills = Employees.Skills;
$scope.Status = Employees.Status;
$scope.add = function () {
$scope.EmployeeDetails.push({
Name: $scope.Name,
Code: $scope.Code,
Is_Intern: $scope.Is_Intern,
DateOfJoining: $scope.DateOfJoining,
Skills: $scope.Skills,
Status: $scope.Status,
});
$scope.id = '';
$scope.Code = '';
$scope.Is_Intern = '';
$scope.DateOfJoining = '';
$scope.Skills = '';
$scope.Status = '';
};
function select(Name) {
for (let i = 0; i < $scope.EmployeeDetails.length; i++) {
if ($scope.EmployeeDetails[i].Name == Name) {
return i;
}
}
return -1;
};
$scope.edit = function (Name) {
let index = select(Name);
let emp = $scope.EmployeeDetails[index];
$scope.Name = emp.Name;
$scope.Code = emp.Code;
$scope.Is_Intern = emp.Is_Intern;
$scope.DateOfJoining = emp.DateOfJoining;
$scope.Skills = emp.Skills;
$scope.Status = emp.Status;
}
$scope.save = function () {
let index = select($scope.Name);
$scope.EmployeeDetails[index].Name = $scope.Name;
$scope.EmployeeDetails[index].Code = $scope.Code;
$scope.EmployeeDetails[index].Is_Intern = $scope.Is_Intern;
$scope.EmployeeDetails[index].DateOfJoining = $scope.DateOfJoining;
$scope.EmployeeDetails[index].Skills = $scope.Skills;
$scope.EmployeeDetails[index].Status = $scope.Status;
$scope.Name = '';
$scope.Code = '';
$scope.Is_Intern = '';
$scope.DateOfJoining = '';
$scope.Skills = '';
$scope.Status = '';
}
$scope.deleteRow = function (emp, row) {
row.isActive = true;
setTimeout(function () {
$scope.delete(emp, row);
});
}
$scope.delete = function (emp, row) {
if (confirm("Are You Sure You want to delete this record ?")) {
$scope.EmployeeDetails.splice(emp, 1)
$scope.$apply();
alert("Deleted");
}
row.isActive = false;
}
$scope.selectedRow = null;
$scope.setClickedRow = function (index) {
$scope.selectedRow = index;
}
});
table {
border-collapse: collapse;
font-family: Arial;
}
td {
border: 1px solid black;
padding: 5px;
}
th {
border: 1px solid black;
padding: 5px;
text-align: center;
}
label,
input {
display: block;
}
label {
margin-bottom: 5px;
}
.highlight {
background: gray;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<body ng-app="myApp" ng-controller="empCtrl">
<table>
<thead>
<th colspan="8">Names of Employees</th>
</thead>
<tbody>
<tr>
<th>Name</th>
<th>Code</th>
<th>Is_Intern</th>
<th>Skills</th>
<th>Status</th>
<th>DateOfJoining</th>
<th colspan="2" style="text-align: center;">Action</th>
</tr>
<tr ng-repeat="emp in EmployeeDetails" ng-class="{'highlight': emp.isActive == true}">
<td>{{emp.Name}} - {{ emp.isActive }}</td>
<td>{{emp.Code}}</td>
<td>{{emp.Is_Intern}}</td>
<td>{{emp.Skills}}</td>
<td>{{emp.Status}}</td>
<td>{{emp.DateOfJoining}}</td>
<td><button ng-click="edit(emp.Nam, emp)">Edit</button></td>
<td><button ng-click="deleteRow($index, emp)">Delete</button></td>
</tr>
</tbody>
<label>
Name
<input ng-model="Name" type="text" />
</label>
<label>
Code
<input ng-model="Code" type="number" />
</label>
<label>
Is_Intern
<input ng-model="Is_Intern" type="text" />
</label>
<label>
Skills
<input ng-model="Skills" type="text" />
</label>
<label>
Status
<input ng-model="Status" type="text" />
</label>
<label>
Date Of Joining
<input ng-model="DateOfJoining" type="text" />
</label>
<label>
<button ng-click="add()">Add</button>
</label>
<button ng-click="save()">Update</button><br><br>
</table>
<br>
</body>
How can i save the titles selecteds of a ng-click in a method in controller?
<div ng-click="selectItem(dimension, $event)">
<span text="{{dimension.title}}" title="{{dimension.title}}">Item 1</span>
</div>
<div ng-click="selectItem(dimension, $event)">
<span text="{{dimension.title}}" title="{{dimension.title}}">Item 2</span>
</div>
<div ng-click="selectItem(dimension, $event)">
<span text="{{dimension.title}}" title="{{dimension.title}}">Item 3</span>
</div>
I am editing a qlik sense extension and need to save the selections in the app.
A better idea would be to identify objects with a unique identifier rather than a title that can be repeated. If the dimension object has an ID(or some other unique value) use it.
Adapt code below to your needs:
var app = angular.module("myModule", []);
app.controller("myCtrl", function($scope) {
var vm = this;
vm.dimensions = [
{
title: 'Title 1'
},{
title: 'Title 2'
},{
title: 'Title 3'
},{
title: 'Title 4'
},{
title: 'Title 5'
},{
title: 'Title 6'
},
];
vm.selected = [];
vm.selectItem = function(item, event) {
if(!vm.isSelected(item)) {
vm.addItem(item);
} else {
vm.removeItem(item);
}
// Show selected list
console.log(vm.selected);
}
vm.isSelected = function(item) {
return vm.selected.indexOf(item.title) != -1;
}
vm.addItem = function(item) {
vm.selected.push(item.title);
}
vm.removeItem = function(item) {
var index = vm.selected.indexOf(item.title);
vm.selected.splice(index, 1);
}
});
.element {
margin: 20px;
line-height: 10px;
border-bottom: 1px solid black;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myModule">
<div ng-controller="myCtrl as ctrl">
<div ng-repeat="dimension in ctrl.dimensions" ng-click="ctrl.selectItem(dimension, $event)">
<span text="{{dimension.title}}" title="{{dimension.title}}" class="element">
{{ dimension.title }}
<span ng-if="ctrl.isSelected(dimension)">- checked</span>
</span>
</div>
</div>
</div>
I am learning angularjs and I came across some behaviour that I can't understand. I render a list of items in ng-repeat, each has a button to remove itself from the $scope's array - this works as expected but once I added a sortable to the list strange things started to happen.
Here is the running example showing the issue:
https://embed.plnkr.co/eQWcxZ7p8CcACfk6Z53X/
In the example - if I move [^] item 4 (Rocket Launcher) to position 1 and use Rocket Launcher's delete [X] button the list gets updated (i.e. item 4 - Rocket Launcher - that was on position 1 is removed) but the other items delete buttons stop working. Basically moving items and deleting them somehow break the bindings (?).
The code:
(function() {
'use strict';
var app = angular.module('myApp', []);
app.controller('myAppController', function($scope) {
$scope.boxes = [];
$scope.removeBoxItem = function(box, item) {
console.log('Removing "' + item.name + '" form box "' + box.name + '"...');
var index = box.items.indexOf(item);
box.items.splice(index, 1);
console.log(box);
};
this.init = function() {
var e;
e = new Box({
name: 'Red box'
});
$scope.boxes.push(e);
e.items.push(new Item({
index: 1,
name: 'Rock'
}));
e.items.push(new Item({
index: 2,
name: 'Scissors'
}));
e.items.push(new Item({
index: 3,
name: 'Paper'
}));
e.items.push(new Item({
index: 4,
name: 'Rocket launcher'
}));
e = new Box({
name: 'Green box'
});
e.items.push(new Item({
index: 1,
name: 'Chuck the Plant'
}));
e.items.push(new Item({
index: 2,
name: 'Hamster'
}));
e.items.push(new Item({
index: 3,
name: 'Tentacle Chow'
}));
$scope.boxes.push(e);
};
this.init();
});
app.directive("sortable", ["$timeout", function($timeout) {
return {
template: '<div class="sortable" ng-transclude></div>',
transclude: true,
scope: {
'handle': '#'
},
link: function(scope, element, attrs) {
$timeout(function() {
//console.log(element)
var sortable = element.find('> div');
console.log(sortable[0]);
scope.sortable = Sortable.create(sortable[0], {
handle: scope.handle || null
});
});
}
};
}]);
}());
function Box(args) {
this.name = args.name || null;
this.items = [];
}
function Item(args) {
this.index = args.index || null;
this.name = args.name || null;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" />
<style>
.container {
border: 1px solid #929292;
padding: 5px;
}
.header {
font-size: 1.2rem;
padding: 10px 15px;
background-color: #F5F5F5;
border-bottom: 2px solid #E2E2E2;
}
.body {
background-color: #F2F2F2;
padding: 10px 10px;
margin-bottom: 10px;
}
.body .item {
border: 1px solid #D2D2D2;
padding: 5px;
margin-bottom: 5px;
}
.body .options {
float: right;
}
.body .options .delete {
cursor: pointer;
}
.body .options .handle {
cursor: move;
}
.debug {
margin-top: 20px;
border-top: 1px dotted #929292;
}
</style>
</head>
<body>
<div ng-app="myApp" ng-controller="myAppController as appCtrl">
<div class="container">
<div ng-repeat="box in boxes">
<div class="header">{{ box.name }}</div>
<div class="body">
<div data-sortable="" data-handle=".handle">
<div class="item" ng-repeat="item in box.items">
{{item.index }}) {{ item.name }}
<div class="options">
<span ng-click="removeBoxItem(box, item)" class="delete">[X]</span>
<span class="handle">[^]</span>
</div>
</div>
</div>
</div>
</div>
<div class="debug">
<pre>{{ boxes | json }}
</pre>
</div>
</div>
</div>
<script data-require="jquery#3.1.1" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script data-require="Sortable.js#1.6.0" data-semver="1.6.0" src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.6.0/Sortable.js"></script>
<script data-require="angular.js#1.6.6" data-semver="1.6.6" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.js"></script>
<script src="script.js"></script>
</body>
</html>
I am confused by this, in my real code things get even more broken - I made a collapsible directive that surrounds the "Boxes" so I can open and manipulate one at a time - in that case moving item 4 to position 1 and deleting it removes all items from the view (but not from the $scope). Than adding new item to the $scope's array causes items to correctly reappear. For now I created simpler version as I guess this is all somehow connected.
I am aware the sortable should set the objects indexes etc but for now I'd like to understand what is happening. I suspect I have some issues with understanding what is going on with scopes (?). Would be grateful for any help.
I've created a sample application in angularjs.
I've different variables(colorNew and numberNew) which hold the value of similar operation.
How can I optimize the code(create a method), so that I can reuse my angular.forEach as well as split method shown in the code instead of writing them multiple times?
Here's the code:
angular.module('myApp', [])
.controller('myCtrl', ['$scope', function($scope){
$scope.myData = [
{
'car': 'Ford',
'color': 'Black, White, Blue',
'number': '1, 2, 3',
'model': 'Figo'
}, {
'car': 'Ford',
'color': 'Red, Black, Silver',
'number': '4,5',
'model': 'Endeavour'
},{
'car': 'Jaguar',
'color': 'White',
'number': '6',
'model': 'F-Type'
},
];
$scope.getData = function(){
$scope.color = this.car.color.split(',');
$scope.number = this.car.number.split(',');
console.log($scope.color);
$scope.colorNew = angular.forEach($scope.color, function() {
return $(this);
}).join(' | ');
$scope.numberNew = angular.forEach($scope.number, function() {
return $(this);
}).join(' | ');
console.log($scope.colorNew);
console.log($scope.numberNew);
};
}]);
.parent {
border: 1px solid lightgrey;
border-radius: 5px;
background-color: skyblue;
height: 100px;
margin-top: 5px;
padding: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<button id="createData">Create Data</button>
<div class="container">
<div ng-repeat="car in myData" class="parent">
<div>
<label>Car:</label>
<span>{{car.car}}</span>
</div>
<br />
<div>
<label>Model:</label>
<span>{{car.model}}</span>
</div>
<br />
<button ng-click="getData(obj)">Click Me!</button>
</div>
</div>
</div>
so if I loop my markers with info-window, info-window show all info about all markers,no separately.I tried also use filter and filtered loop in info-window but not worked..
And sorry for my english i am not a native speaker..
info-window and marker image how look like my problem
my code here
<div class="googleMaps">
<ng-map id="map" style="height: 224px" zoom="14" center="currentLocation()" ng-init="currentLocation()">
<marker animation="DROP"
position="currentLocation()"
icon="../img/tagGoogle.png" >
</marker>
<marker animation="DROP"
ng-repeat="results in xResult"
value="{{results.name}}"
position="{{results.lat +','+ results.lng}}"
on-click="showInfoWindow(1)">
</marker>
<info-window id="1">
<div ng-non-bindable="">
<div ng-repeat="results in xResult">
<div>
shop id:{{ results.id }} name:{{results.name}}<br>
</div>
</div>
</div>
</info-window>
</ng-map>
</div>
If I understood you properly, you would like to display info window with information that corresponds to the clicked marker. If so, the following example demonstrates how to accomplish it:
angular.module('mapApp', ['ngMap'])
.controller('mapController', function($scope, NgMap) {
NgMap.getMap().then(function(map) {
$scope.map = map;
});
$scope.cities = [
{ id: 1, name: 'Oslo', pos: [59.923043, 10.752839] },
{ id: 2, name: 'Stockholm', pos: [59.339025, 18.065818] },
{ id: 3, name: 'Copenhagen', pos: [55.675507, 12.574227] },
{ id: 4, name: 'Berlin', pos: [52.521248, 13.399038] },
{ id: 5, name: 'Paris', pos: [48.856127, 2.346525] }
];
$scope.showCity = function(event, city) {
$scope.selectedCity = city;
$scope.map.showInfoWindow('myInfoWindow', this);
};
});
<script src="https://maps.google.com/maps/api/js"></script>
<script src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<script src="app.js"></script>
<div ng-app="mapApp" ng-controller="mapController">
<ng-map default-style="true" zoom="5" center="59.339025, 18.065818">
<info-window id="myInfoWindow">
<div ng-non-bindable>
<h4>{{selectedCity.name}}</h4>
</div>
</info-window>
<marker ng-repeat="c in cities"
position="{{c.pos}}" title="{{c.name}}" id="{{c.id}}" on-click="showCity(event, c)">
</marker>
</ng-map>
</div>
Thx for answer...I already fix it too..
So my solution..
<div class="googleMaps">
<div id="map" ng-init="currentLocation()"></div>
</div>
<form id="coffeForm" ng-submit="submitForm()">
<div class="textField" ng-repeat="marker in markers | orderBy : 'title'" ng-class="{ 'selected-class-name': $index == selectedIndex }"
ng-click="itemClicked($index)">
<div flex id="class" class="text-center">
<label flex href="#" class="text-center" ng-click="openInfoWindow($event, marker)">{{marker.title}}
<input flex id="Id" type="radio" name="Id" ng-model="form.Id" value="{{marker.id}}" /></label>
</div>
</div>
<a class="coffGoBtn text-center" href="#/orderCoffe" ng-click="submitForm()">Pokracuj</a>
</form>
$scope.currentLocation = function() {
var options = {
enableHighAccuracy: true
};
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (pos) {
$scope.position = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
$scope.Lat = pos.coords.latitude;
$scope.Long = pos.coords.longitude;
var postData = $.param({
arr1: JSON.stringify({
latit: $scope.Lat
}),
arr2: JSON.stringify({
longit: $scope.Long
})
});
console.log(postData);
$http({
method: 'POST',
url: 'range.php',
data: postData,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
dataType: JSON
}).success(function (res) {
$scope.xResult = [];
$scope.xResult = res;
var setPosition = $scope.position;
var mapOptions = {
zoom: 15,
center: $scope.position,
disableDefaultUI:true,
//scrollwheel: false,
//navigationControl: false,
//mapTypeControl: false,
//scaleControl: false,
draggable: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
icon: ourMarker
};
$scope.map = new google.maps.Map(document.getElementById('map'), mapOptions);
var ourMarker = new google.maps.Marker({
position: setPosition,
map: $scope.map,
title: 'its me',
icon: 'img/tagGoogle.png'
});
ourMarker.setMap($scope.map);
$scope.markers = [];
$scope.logos= [];
$scope.names =[];
var infoWindow = new google.maps.InfoWindow();
var createMarker = function(info){
var marker = new google.maps.Marker({
map: $scope.map,
position: new google.maps.LatLng(info.lat, info.lng),
title: info.name,
logo: info.img,
id: info.id,
icon: "img/Place.png"
});
marker.content = '<div class="infoWindowContent">' + info.name + ", " +"<br>"+ "vzdialenost: " + info.distance * 1000 + "m" +'</div>';
google.maps.event.addListener(marker, 'click', function(){
infoWindow.setContent('<h6>' + marker.title + '</h6>' + marker.content);
infoWindow.open($scope.map, marker);
$log.info(infoWindow);
});
$scope.markers.push(marker);
};
for (var i = 0; i < res.length; i++){
createMarker(res[i]);
}
$scope.openInfoWindow = function(e, selectedMarker){
google.maps.event.trigger(selectedMarker, 'click');
};
}).error(function (error) {
console.log(error);
});
},
function (error) {
alert('Unable to get location: ' + error.message);
}, options);
}
else {
alert("Please reload page or click on the Set Position button or your browser does not support geolocation services.");
}