I know that similar questions have been asked and I have tried there answers but they have not worked for me, hence I'm asking new question, here is my code:
hbs:
<link data-require="bootstrap-css#*" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" />
<title>UI</title>
<div ng-controller="appCtrl">
<button type="button" ng-click="openModal()">Abc</button>
</div>
<script type="text/ng-template" id="checklistModal.html">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="cancel()"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Modal</h4>
</div>
<div class="modal-body" id="modal-body">
<div style="padding-left: 3%; padding-right: 3%; margin-bottom: 8%;">
<div class="row">
<div class="col-md-12">
<table style="border-bottom: 2px solid #cccccc" class="table table-bordered">
<thead style="display:table;width:100%;table-layout:fixed;">
<tr>
<th style="text-align:center;" width="15%"></th>
<th style="text-align:center;" width="15%">Pending</th>
<th style="text-align:center;" width="15%">Done</th>
</tr>
</thead>
<tbody style="display:block;height:164px;overflow:auto;">
<tr style="display:table;width:100%;table-layout:fixed;">
<td style="text-align:center;">Task 1</td>
<td style="text-align:center;"></td>
<td style="text-align:center;"></td>
</tr>
</tbody>
</table>
<button class="btn btn-primary pull-right" ng-click="" style="float:right;">Save</button>
</div>
</div>
</div>
</div>
</script>
And here is corresponding js:
var app = angular.module("demoApp", ['ui.bootstrap']);
app.controller("appCtrl",['$scope', '$uibModal', function($scope, $uibModal) {
'use strict';
$scope.openModal = function(){
var parentElem = parentSelector ?
angular.element($document[0].querySelector('.modal-demo ' + parentSelector)) : undefined;
var modalInstance = $uibModal.open({
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: "checklistModal.html",
controller: 'ChecklistModalInstanceCtrl',
scope: $scope,
size: "lg",
appendTo: parentElem,
resolve: {
}
});
modalInstance.result.then(function (selectedItem) {
$ctrl.selected = selectedItem;
}, function () {
});
}
}]);
app.controller('ChecklistModalInstanceCtrl', function($scope) {
});
Error I get is: Unknown provider: $uibModalProvider <- $uibModal <- appCtrl
If, I change first line of js:
var app = angular.module("demoApp", []);
Error I get is: Failed to instantiate module demoApp
Answers to similar questions I found did not work, can anyone please help?
You need to inject ui.bootstrap as a dependency to your module,
var app = angular.module('app',['ui.bootstrap']);
also add the reference as well
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js"></script>
Related
I have a controller that I use in two places: in a ng-view and in a ng-include. These places are not child or parent to each other, but I want to some changes made in the ng-view affect to ng-include as well. How can I do that?
Here is plunker with these parts of code.
I want to when "Edit user" is clicked the user.userName from the table shows in the popup.
index.html
<body>
<div ng-view></div>
<div ng-include="'edit-user.html'"></div>
<script src="app.js"></script>
<script src="UsersController.js"></script>
</body>
app.js
var app = angular.module('myApp', ['ngRoute', 'ui.materialize'])
.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'users.html',
controller: 'UsersController'
})
.otherwise({redirectTo: '/'});
}]);
users.html
<h4>Users</h4>
<table class="striped highlight">
<thead>
<tr>
<th data-field="displayName">Display Name</th>
<th data-field="userName">User Name</th>
<th data-field="registered">Registered</th>
<th data-field="updated">Updated</th>
<th data-field="email">Email</th>
<th data-field="authority">Authority</th>
<th data-field="edit">Edit</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td ng-bind="user.displayName"></td>
<td ng-bind="user.userName"></td>
<td ng-bind="user.registered"></td>
<td ng-bind="user.updated"></td>
<td ng-bind="user.email"></td>
<td ng-bind="user.authority"></td>
<td><a class="collection-item waves-effect waves-teal" modal open="openModal" ng-click="openModalFunc(user)">Edit user</a></td>
</tr>
</tbody>
</table>
<a data-target="edit-user" class="hide" modal open="openModal">Edit user</a>
UsersController.js
app.controller('UsersController', ['$scope', function($scope) {
// create fake users
$scope.users = [
{
displayName: 'Alexander',
registered: '02-07-2017',
updated: '02-07-2017',
email: 'alex#gmail.com',
authority: 'admin',
userName: 'Alex'
},
{
displayName: 'Lev',
registered: '02-07-2017',
updated: '02-07-2017',
email: 'lev#gmail.com',
authority: 'guest',
userName: 'Lev'
}
]
$scope.openModal = false;
$scope.openModalFunc = function(user) {
$scope.openModal = true;
$scope.selectedUser = user;
Materialize.toast('Awesome, we did it!', 4000);
}
}]);
edit-user.html
<div id="edit-user" class="modal col l3" ng-controller="UsersController">
<div class="modal-content">
<h4>{{selectedUser.userName}}</h4>
</div>
<div class="modal-footer">
<a class="modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
</div>
</div>
If it is not very big application then you can use $broadcast from one controller and catch that using $on..
You can find more information here.
I've found that better solution is to move your data that need to be shared into the upper general scope.
the pushed data from the model is not reflecting in the first table. It is there in console. The fiddle link is attached with this please help me on this.
fiddle link ---- http://jsfiddle.net/8MVLJ/2649/
html=========
<script src="https://code.angularjs.org/1.4.9/angular.min.js"></script>
<script src="https://rawgit.com/dwmkerr/angular-modal-service/master/dst/angular-modal-service.js"></script>
<div class="container" ng-app="app" ng-controller="Controller">
<div class="row">
<div class="col-xs-12">
<table class="table table-striped table-bordered">
<thead>
<th>Attribute Name</th>
<th>Attribute Value</th>
</thead>
<tbody>
<tr ng-repeat="newdetail in newDetails">
<td>
<p ng-model="detail">{{newdetail.attrName}} </p>
</td>
<td>
<p ng-model="detailValue">{{newdetail.userAttrValue}} </p>
</td>
</tr>
</tbody>
</table>
<a class="btn btn-default" href ng-click="show()">Select Attribute</a>
<script type="text/ng-template" id="modal.html">
<div class=" ngdialog-messsage modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" ng-click="close('Cancel')" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-xs-12">
<table class="table table-striped table-bordered">
<thead>
<th>
<input type="checkbox" ng-model="allSelected" ng-model-options="{getterSetter: true}">
</th>
<th>Attribute Name</th>
<th>Attribute Value</th>
</thead>
<tbody>
<tr ng-repeat="detail in details">
<td>
<input type="checkbox" ng-model="detail.Selected">
</td>
<td>
<p ng-model="detail">{{detail.attrName}}</p>
</td>
<td>
<select ng-model="detail.user_attr_value" ng-init="detail.user_attr_value=detail.attr_value_Ind.split(',')[0]" class="form-control full-width">
<option ng-repeat="option in detail .attr_value_Ind.split(',')" value="{{option}}">{{option}}</option>
</select>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal-footer">
<div class="form-group">
<input type="button" class="btn btn-primary" value="Add Selected" ng-click="add();close('Cancel')">
<input type="button" class="btn btn-danger " ng-click="checkAll(details.length)" value="Clear">
</div>
</div>
</div>
</div>
</div>
</script>
</div>
</div>
</div>
js===================
var app = angular.module('app', ['angularModalService']);
app.controller('Controller', function($scope, $element, ModalService) {
$scope.newDetails = [{
"attrName": "userType",
"userAttrValue": "Customer",
"userOrGroupId": "aaaazzz8522",
}];
$scope.add = function() {
angular.forEach($scope.details, function(detail) {
if (detail.Selected == true) {
$scope.newDetails.push({
'attrName': detail.attrName,
'attrName': detail.user_attr_value
});
$element.modal('hide');
close($scope.newDetails, 500);
console.log("loop", $scope.newDetails);
}
});
};
$scope.show = function() {
ModalService.showModal({
templateUrl: 'modal.html',
controller: "Controller"
}).then(function(modal) {
modal.element.modal();
modal.close.then(function(result) {});
});
};
//=================================================
$scope.close = function(result) {
close(result, 600);
};
$scope.details = [{
"attrName": "region",
"attrType": "USER",
"attr_value_Ind": "CHN-N,CHN-S,CHN-C",
"buId": "DEFAULT",
}];
var getAllSelected = function() {
var selecteddetails = $scope.details.filter(function(detail) {
return detail.Selected;
});
return selecteddetails.length === $scope.details.length;
}
var setAllSelected = function(value) {
angular.forEach($scope.details, function(detail) {
detail.Selected = value;
});
}
$scope.allSelected = function(value) {
if (value !== undefined) {
return setAllSelected(value);
} else {
return getAllSelected();
}
}
$scope.checkAll = function(Count) {
angular.forEach($scope.details, function(details) {
details.Selected = false;
});
};
});
i have updated your fiddle please check and review.http://jsfiddle.net/8MVLJ/2652/
it's not pushing it's value because you have pass scope in your modal controller and set parent scope like this
ModalService.showModal({
templateUrl: 'modal.html',
controller: "Controller",
scope:$scope <-- added here scope
}).then(function(modal) {
modal.element.modal();
modal.close.then(function(result) {});
});
and add $parent to push your value like this
$scope.$parent.newDetails.push({ <-- added $parent here
'attrName': detail.attrName,
'userAttrValue': detail.user_attr_value
});
I just received a project which contains angularjs in it, I need to do someting and i don´t now what am I doing wrong since I'm a noob in angularjs matters.
The context:
This is just a part of the whole project, all the angular files in the project are configured with gulp.
I have a html page(page1.html) which has a button and a table, this html is controlled by an ng-controller(controller.js), in the html i have a button with an ng-click function.
This function opens a $uibModal which has its own controller and a templateUrl. the templateUrl is in the html file inside an <script></script> tag.
The controller of the modal(controller2) is in the same file as the main controller(controller1)
When the modal opens I see one text input, I enter some text then press the add button, the modal closes and in my main html page one row of the table is added with the entered text in the text input.
The problem:
The table on each row next to the text has 2 buttons with ng-click functions, one for delete an one for edit, when the rows are added from the beginning of the compilation they work fine, but when the rows are dynamically added from the modal they don't do anything. I have read some questions with similar problems where the $compile service do the work, but I do not know how to apply it on this case.
Any help will be enormously appreciated.
The html file
<div ng-controller="CreateObsController">
<script type="text/ng-template" id="add-observations.html">
<div class="modal-header">
<h3 class="modal-title">{{ modalTitle }}</h3>
</div>
<div class="modal-body">
<form class="form-horizontal" novalidate name="form">
<div class="form-group">
<label for="inputType" title="Item" class="control-label col-md-2">Item</label>
<div class="col-md-3 col-sm-3 col-xs-12">
<input type="text" title="Ingrese Item" id="txtIdObs" class="form-control " value="{{count}}">
</div>
</div>
<div class="form-group">
<label for="inputType" title="Observation" class="control-label col-md-2">Observation</label>
<div class="col-md-10">
<textarea title="Enter observation" ng-maxlength="50" ng-model="observacionAdd" id="observationDetail" class="form-control custom-control " rows="3" style="resize:none" placeholder="Observation" required></textarea>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="tablaObsAddOne()()"
button-spinner="isProcesando">
Add obs
</button>
</div>
</script>
<script>
//work but only if the rows are in the html before executing the page.
function RemoveObservation(idx) {
var row = document.getElementById(idx);
row.parentNode.removeChild(row);
}
</script>
<br />
<div class="panel panel-primary">
<div class="form-horizontal ">
<div class="panel-heading col-md-11" style="background-color:#2196F3; color:white; max-width: 88%; box-shadow: 1px 5px 20px #ccc;" ng-click="paneCollapseObs=!paneCollapseObs">
<span >OBSERVATIONS</span>
<i class="pull-right fa" ng-class="paneCollapseObs ? 'fa-chevron-down' : 'fa-chevron-left'"></i>
</div>
<div class="col-md-1" align="left">
<button type="button" title="add observation" class="btn btn-primary btn-md" style="font-size:20px; background-color:#2196F3;" ng-click="AddObservation()">+</button>
</div>
<div class="panel-body" style="float: left; padding-top: 0px; box-shadow: 1px 15px 30px #ccc; max-width: 98%;" ng-hide="paneCollapseObs">
<br />
<form class="form-horizontal">
<div class="form-group">
</div>
<div class="container-fluid table-responsive table-DescRec espacio">
<div class="row col-md-12 col-sm-12 col-xs-12">
<table id="tableObservations" class="table table-striped table-condensed table-bordered table-hover table-parametros ">
<thead>
<tr class="fondoFila colorLetras">
<th class="col-md-1 col-xs-2 text-center">
<label title="Item">Item</label>
</th>
<th class="text-left col-md-9 col-sm-offset-1 ellipsis">
<label title="Observation">Observation</label>
</th>
<th class="text-center col-md-1 col-sm-1 col-sm-offset-1 col-xs-2">
<label title="Edit">Edit</label>
</th>
<th class="text-center col-md-1 col-sm-1 col-sm-offset-1 col-xs-2">
<label title="Delete">Delete</label>
</th>
</tr>
</thead>
</table>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
the controller file
(function () {
'use strict';
function CreateObsController($scope, $rootScope, $compile, $log, $filter, $timeout, $state, toaster, authService, hash,
$uibModal, uiGridConstants, i18nService, blockUI, $window, $document, RutHelper) {
$scope.init = init;
$scope.AddObservation = AddObservation;
$scope.RemoveObservation = RemoveObservation;
function RemoveObservation(idx) {
var row = document.getElementById(idx);
row.parentNode.removeChild(row);
}
function AddObservation() {
$uibModal.open({
animation: true,
templateUrl: 'add-observations.html',
controller: 'ModalAddObsController',
backdrop: 'static',
size: 'lg',
resolve: {
}
});
}
function clear() {
$scope.paneCollapseObs = true;
}
function init() {
clear();
}
$scope.init();
};
angular
.module(configData.nameApp)
.controller('CreateObsController', CreateObsController);
CreateObsController.$inject = ['$scope', '$rootScope', '$compile','$log', '$filter', '$timeout', '$state',
'toaster', 'authService', 'hash', '$uibModal', 'uiGridConstants', 'i18nService', 'blockUI', '$window', '$document', 'RutHelper'];
})();
(function () {
'use strict';
function ModalAddObsController($rootScope, $scope, $timeout, $log, $uibModalInstance, authService, toaster, $window, hash, $document) {
$scope.modalTitle = 'Observations';
$scope.tablaObsAddOne = tablaObsAddOne;
$scope.addObservaciones = addObservaciones;
$scope.count = rowCountObservations();
function addObservaciones() {
var table = document.getElementById("tableObservations");
var row = table.insertRow(-1);
row.className = "text-center";
row.id = 'filaObs' + (rowCountObservations() - 1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
cell1.className = "col-md-1 col-xs-2 text-center";
cell2.className = "text-left col-md-9 col-sm-offset-1 ellipsis";
cell3.className = "text-center col-md-1 col-sm-1 col-sm-offset-1 col-xs-2";
cell4.className = "text-center col-md-1 col-sm-1 col-sm-offset-1 col-xs-2";
cell1.innerHTML = rowCountObservations() - 1;
cell2.innerHTML = document.getElementById("observationDetail").value;
cell3.innerHTML = '<button class="btn btn-xs btn-info btn-ico" ng-click="EditObservacion(filaObs' + (rowCountObservations() - 1) + ')"><i class="material-icons" style="font-size:24px">edit</i></button>';
cell4.innerHTML = '<button class="btn btn-xs btn-danger btn-ico" ng-click="RemoveObservation(filaObs' + (rowCountObservations() - 1) + ')"><i class="material-icons" style="font-size:24px">delete</i></button>';
observationDetail.value = "";
txtIdObs.value = rowCountObservations();
}
function rowCountObservations() {
var x = document.getElementById("tableObservations").rows.length;
return x;
}
function tablaObsAddOne() {
var table = document.getElementById("tableObservations");
if (document.getElementById("observationDetail").value.length != 0) {
addObservaciones();
$uibModalInstance.close('ok');
} else {
alert("enter text");
}
}
}
angular
.module(configData.nameApp)
.controller('ModalAddObsController', ModalAddObsController);
ModalAddObsController.$inject = ['$rootScope', '$scope', '$timeout', '$log', '$uibModalInstance', 'authService', 'toaster', '$window', 'hash', '$document'];
})();
When you trigger insert this will do some changes with DOM the problem is that Angular have no idea that some states are changed. I am not sure in your case but you can try this. The $apply will make angular to know about any changes outside the angular world.
function tablaObsAddOne() {
var table = document.getElementById("tableObservations");
if (document.getElementById("observationDetail").value.length != 0) {
$scope.$apply(function() {
addObservaciones();
})
$uibModalInstance.close('ok');
} else {
alert("enter text");
}
}
But why you don't just use "ng-repeat" on your table
$scope.data = [
name: 'test',
value: 'test',
] // store here your data;
$scope.actionEdit = function($index) {
//code;
}
$scope.actionDelete = function($index) {
//code;
}
<tbody>
<tr data-ng-repeat="item in data track by $index">
<td>{{item.name}}</td>
<td>{{item.value}}</td>
<td><button data-ng-click="actionEdit($index)">Edit</button></td>
<td><button data-ng-click="actionDelete($index)">Delete</button></td>
</tr>
</tbody>
And here just:
function tablaObsAddOne() {
var table = document.getElementById("tableObservations");
if (document.getElementById("observationDetail").value.length != 0) {
$scope.data.push({
name: 'test1',
value: 'test2'
});
$uibModalInstance.close('ok');
} else {
alert("enter text");
}
}
This is just one example of what you can do.
But for more details just read more about angular directives like ng-repeat and others this will make your life easier.
I want to use angular modal for CRUD operation, so for firing the modal we have button by id modalFire in ng-controller="ModalDemoCtrl" , this is my modal:
<div ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">....</h3>
</div>
<div class="modal-body">
<form id="productForm" novalidate>
<div>
<label for="ProductName"> productName :</label>
<input type="text" name="ProductName" id="ProductName" ng-model="model.ProductName" value="" required />
</div>
<div style="margin:10px">
<label for="Price">price :</label>
<input type="text" name="Price" id="Price" ng-model="model.Price" />
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="Save()" ng-disabled="productForm.$invalid">save</button>
<button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
</div>
</script>
<button type="button" id="modalFire" class="btn btn-default modalBtn" ng-click="open()">UpdateProduct</button>
</div>
and it's controller:
App.controller('ModalDemoCtrl', function ($scope, $modal) {
$scope.open = function (size) {
var modalInstance = $modal.open({
animation: true,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: size,
resolve: {
items: function () {
return $scope.items;
}
}
});
};
});
App.controller('ModalInstanceCtrl', function ($scope, $modalInstance, $http) {
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});
and i have a grid that shows ProductList :
<div ng-controller="ProductController" ng-init="GetAllProducts()">
<div class="row" style="margin-top:90px" ng-show="!ShowGrid">
<article class="widget">
<header class="widget__header">
<div class="widget__title">
<i class="pe-7s-menu"></i><h3>ProductList</h3>
</div>
<div class="widget__config">
<i class="pe-7f-refresh"></i>
<i class="pe-7s-close"></i>
</div>
</header>
<div class="widget__content table-responsive">
<table class="table table-striped media-table">
<thead style="background-color:rgba(33, 25, 36,0.1)">
<tr>
<th style="width:30%">price</th>
<th style="width:30%">productName</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in Products">
<td>{{product.Price}}</td>
<td>{{product.ProductName}}</td>
</tr>
</tbody>
</table>
</div>
</article>
</div>
</div>
so, i want a way to add a button or <a> element for each row in grid that can fire the modal, is there any way?
Unless I misunderstand your question, why not just add the button to your ng-repeat in your table. For example:
<table class="table table-striped media-table">
<thead style="background-color:rgba(33, 25, 36,0.1)">
<tr>
<th>Price</th>
<th>ProductName</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in Products">
<td>{{product.Price}}</td>
<td>{{product.ProductName}}</td>
<td><button ng-click="loadItem(product)>Edit</button></td>
</tr>
</tbody>
</table>
Then inside your controller, just pass the product into your modal load function. For example:
$scope.loadItem = function(product){
var modalInstance = $modal.open({
animation: true,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
product: function () {
return product;
}
}
});
};
See how you can pass the product to the function, and then use resolve to pass the product into the modal. In your modal controller you would attach the product to the $scope, and use it as you would any other view.
I trying to do a modal that show events in a table but when i do the ng-repeat only show one item and i don't know why.
If someone can help me i will be very grateful,
The html is the following:
<!DOCTYPE html>
<html lang="en" ng-app="dashboard">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>LiftEye</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.0.js"></script>
<script src="../controllers/dashboardController.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="../js/angular-tablescroll.js"></script>
<script type="text/javascript" src="https://code.angularjs.org/1.3.9/angular-resource.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<link href="../bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="../bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">
<link href="../bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
</head>
<body ng-controller="dashboardController">
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- /.navbar-header -->
<ul class="nav navbar-top-links navbar-right">
<div id="page-wrapper" >
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Operación</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row" >
<div class="col-lg-8 col-md-8">
<div class="panel " STYLE="background-color: #eaeaea">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
</div>
<div class="col-xs-9 text-right">
</div>
</div>
</div>
</div>
</div>
<!-- /.row -->
<!-- /.panel -->
<div class="panel panel-default" >
<div class="panel-heading">
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="row">
<div class="col-lg-3">
<div >
<table class="table table-bordered table-hover table-striped dataTable no-footer" data-sort-name="name" data-sort-order="desc">
<tr role = "row" class="info text-center">
<th ng-click="order('msisdn')">Número Teléfono</th>
<th ng-click="order('icc')">ICC</th>
<th ng-click="order('imei')">IMEI</th>
<!--th>IMEI</th-->
<th ng-click="order('ActivationStatus')">Estado</th>
<th ng-click="order('sitename')">Instalación</th>
<th ng-click="order('siteaddress')">Dirección</th>
<th ng-click="order('sitecity')">Ciudad</th>
<th ng-click="order('sitezip')">Código Postal</th>
<th ng-click="order('phonedesc')">Modelo Teléfono</th>
<th ng-click="order('ContractingMode')">VBP</th>
</tr>
<tr class=" text-center" ng-repeat-start="object in objects | filter:searchText | filter:tableFilter | orderBy:predicate:reverse" ng-click="main.activeRow = object.icc" >
<td>{{object.msisdn}}</td>
<td>{{object.icc}}</td>
<td>{{object.imei}}</td>
<td>{{object.ActivationStatus}}</td>
<td>{{object.sitename}}</td>
<td>{{object.siteaddress}}</td>
<td>{{object.sitecity}}</td>
<td>{{object.sitezip}}</td>
<td>{{object.phonedesc}}</td>
<td>{{ object.ContractingMode ? 'Yes': 'No'}}</td>
</tr>
<tr ng-repeat-end ng-show="main.activeRow==object.icc">
<td colspan="3"> <a>Fecha Activación:</a> <div> {{object.DateActivation}}</div> <div><a> Fecha Baja</a> {{object.DateDisconnection}}</div> <div><a> Último Evento HW</a> {{object.LastHWEvent}}</div></td>
<td colspan="4"> <a>Último Evento Humano:</a> <div> {{object.LastHumanEvent}}</div> <div><a> Último Evento Test</a> {{object.LastTestEvent}}</div> <a>Comentarios:</a> <div> {{object.comments}}</div> </td>
<td colspan="2"> <div><a> Rae1: </a> {{object.rae1}}</div> <div><a> Rae2: </a> {{object.rae2}}</div> <a>Pin1:</a> <div> {{object.pin1}}</div> <div><a> Pin2: </a> {{object.pin2}}</div></td>
<td colspan="1"> <div> <button class="btn btn-info" ng-click="open(object)">Eventos</button></div> </td>
<div >
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">Eventos</h3>
</div>
<div class="modal-body" >
<table class="table" ng-tablescroll="options">
<thead>
<tr>
<th >Fecha</th>
<th >Tipo Evento</th>
<th >Origen Evento</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="evento in eventos | limitTo:5">
<td>{{evento.eventtime}}</td>
<td>{{evento.eventtype}}</td>
<td>{{evento.parenttype}}</td>
</tr></tbody></table>
</div>
<div class="modal-footer">
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>
</div>
</tr>
</table>
</div>
<!-- /.table-responsive -->
</div>
</div>
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
<!-- /.col-lg-4 -->
</div>
<!-- /.row -->
</div>
</body>
</html>
And the controller is the following. The modal is inside a table with parent child.
var app =angular.module('dashboard',['ui.bootstrap']);
app.controller('dashboardController', function($scope, $http,$modal ){
$scope.objects=[{}];
$scope.objects={};
$scope.objects=[];
$scope.grupos =[{}];
$scope.longitud =[{}];
$scope.eventos =[{}];
var URLEvents = "/api/events/";
//Abrimos modal y les pasamos los eventos de esa instalación
$scope.open = function (object) {
$http.get(URLEvents + object.liftsiteid, $scope)
.success(function (data) {
var events = data;
angular.forEach(events, function(event) {
$scope.eventos = event;
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: 'lg',
resolve: {
items: function () {
return $scope.eventos;
}
}
});
})
})
.error(function (data) {
window.alert('Something Wrong...');
});
};
var URLOperation ="/api/sites";
//Funci?n que devuelve las instalaciones de un usuario
$http.get(URLOperation, $scope)
.success(function(data) {
var groups = data;
angular.forEach(groups, function(group) {
var group2 = group;
angular.forEach(group2.sites, function(group3){
$scope.longitud.push(group3);
$scope.objects.push(group3);
$scope.predicate = 'msisdn';
$scope.reverse = true;
$scope.order = function(predicate) {
$scope.reverse = ($scope.predicate === predicate) ? !$scope.reverse : false;
$scope.predicate = predicate;
};
})
});
})
.error(function(data) {
window.alert('Something Wrong...');
});
});
//Abrimos el modal y le enviamos los eventos
app.controller('ModalInstanceCtrl', function ($scope, $modalInstance, items, $anchorScroll){
$anchorScroll();
$scope.eventos =[{}];
$scope.eventos.push(items);
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});
You're providing a lot of code - do you have the same issue for all of your lists and tables?
My first guess would be the initialization of the arrays:
$scope.grupos =[{}];
Try setting an empty array instead of an array with the first element being empty:
$scope.grupos = [];
Since you push new elements into the arrays when receiving your data, the first empty item will always be stuck in the data and might lead to your issues.
Another issue is in getting the "eventos": $scope.eventos = event;
I think this should be a push instead: $scope.eventos.push(event);
No offense - maybe you should try to get a better understanding of these basic concepts in Javascript (you're already using most of them correctly, but some look kind of mixed up):
Object initialization: var obj = {}; - this would be an empty object with no properties.
Array initialization: var arr = []; - this would be an empty array with no elements.
Therefore var x = [{}] will result in x being an array with an empty object.
You're trying to open one modal per event rather than one modal for all of the events.
Try replacing:
var events = data;
angular.forEach(events, function(event) {
$scope.eventos = event;
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: 'lg',
resolve: {
items: function () {
return $scope.eventos;
}
}
});
})
with
$scope.eventos = data;
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: 'lg',
resolve: {
items: function () {
return $scope.eventos;
}
}
});
and replace your modal instance with:
app.controller('ModalInstanceCtrl', function ($scope, $modalInstance, items, $anchorScroll){
$anchorScroll();
$scope.eventos = items;
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});