My web page has 3 bootstrap tabs with data some data being populated run time. After page loads, tab1 looks fine and when I click on other tabs, whole body reloads and tab1 displays. I do not see any errors in Console.
HTML:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
<div class="container" -ng-controller="incidentSummaryCtrl" >
<div class="panel panel-primary">
<div class="panel-heading"><h3>Incident {{c.data.incidentData[0].incidentId}} </h3> </div>
<div class="panel-body" style="padding:0px">
<div class="panel-group">
<div class="container">
<div class="row text-center">
<h1 class="white"></h1>
</div>
<div class="row">
<div class="col-md-10">
<div class="tab" role="tabpanel">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Incident Information</li>
<li role="presentation" class="">Potential Indicators</li>
<li role="presentation" class="">Course of Action</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade active in" id="Section1">
<div class="col-md-3 col-xs-3">
<p><label>First Name: </label> {{c.data.incidentData[0].firstName}} </p>
<p><label>Last Name: </label> {{c.data.incidentData[0].lastName}} </p>
<p><label>Email: </label> {{c.data.incidentData[0].email}} </p>
<p><label>Telephone Number: </label> {{c.data.incidentData[0].telephoneNumber}} </p>
<p><label>Reported Date: </label> {{c.data.incidentData[0].createdDate}} </p>
<p><label>Last Updated: </label> {{c.data.incidentData[0].lastUpdated}} </p>
</div>
<div class="col-md-3 col-xs-3">
<p><label>Incident #: </label> {{c.data.incidentData[0].incidentId}} </p>
<p><label>Status: </label> {{c.data.incidentData[0].incidentStatus}} </p>
<p><label>Category: </label> {{c.data.incidentData[0].incidentType}} </p>
<p><label>Organization: </label> {{c.data.incidentData[0].organization}} </p>
<p><label>Department: </label> {{c.data.incidentData[0].department}} </p>
<p><label>Assigned To: </label> {{c.data.incidentData[0].assignedTo}} </p>
</div>
<div class="col-md-12 col-xs-12">
<p><label for="notes">Notes:</label> </p>
<textarea class="form-control" rows="5" id="notes" ng-readonly="true">{{c.data.incidentData[0].note}}</textarea>
</div>
</div> <!-- End of Section1 -->
<div role="tabpanel" class="tab-pane fade" id="Section2">
<label>Extracted Potential Indicators</label>
<table class="table table-condensed table-hover table-bordered">
<thead>
<tr>
<th>No</th>
<th>Ranking</th>
<th>Indicator</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="indicator in c.data.indicatorsData track by $index" >
<td>{{indicator.number}}</td>
<td>{{indicator.urgencyRanking}}</td>
<td>{{indicator.indicatorText}}</td>
<td class="{{indicator.cssClass}}">{{indicator.indicatorStatus}}</td>
</tr>
</tbody>
</table>
</div> <!-- End of Section2 -->
<div role="tabpanel" class="tab-pane fade" id="Section3">
<p><label>Recommendation: </label> {{c.data.courseOfActionsData[0].recommendedName}} </p>
<p><label>Reasoning: </label> {{c.data.courseOfActionsData[0].reasoning}} </p>
<p><label>Select Course of Action: </label>
<select class="form-control" id="sel1" ng-model="selectedValue" style="max-width:700px">
<option ng-repeat="coa in c.data.ListOfCourseOfActionsData track by $index" value="{{coa.name}}" ng-selected="{{defaultvalue == c.data.courseOfActionsData[0].recommendedName}}">{{coa.name}}</option>
</select> </p>
<p><label>Additional Actions: </label> </p>
<div id="actions">
<label class="checkbox-inline"><input type="checkbox" value="" id="sendEmailUpdateToReporter">Send Email Update to Reporter</label>
<label class="checkbox-inline"><input type="checkbox" value="" id="notifyIsp" ng-model="notifyIsp">Notify ISP</label>
<label class="checkbox-inline"><input type="checkbox" value="" id="notifyDomainRegistrar" ng-model="notifyDomainRegistrar">Notify Domain Registrar</label> <br/>
<label class="checkbox-inline"><input type="checkbox" value="" id="sendEmailReceipt">Send Email Receipt to Reporter</label>
<label class="checkbox-inline"><input type="checkbox" value="" id="setStatusOfTicketToResolved">Set Status of Ticket Resolved
</label>
<label class="checkbox-inline"><input type="checkbox" value="" id="notifyProduction">Notify Production</label><br/>
<label class="checkbox-inline"><input type="checkbox" value="" id="resolveAndCloseTicket">Resolve and Close Ticket</label>
<label class="checkbox-inline"><input type="checkbox" value="" ng-model="checked" id="assignToGroup">Assign to Group</label>
<br/>
</div> <br/>
<div class="row">
<div id="assignment" class="col-md-4">
<b>Group Name:</b>
<select id="groupSelectedValue" ng-model="groupSelectedValue" style="max-width:700px" class="form-control">
<option value="Tier1">Tier1</option>
<option value="Tier2">Tier2</option>
<option value="Tier3">Tier3</option>
<option value="Tier4">Tier4</option>
<option value="Tier5">Tier5</option>
<option value="Halo Administrator">Halo Administrator</option>
</select>
</div>
<div class="col-md-4">
<b>Assign To:</b>
<select id="assignTo" ng-model="assignTo" style="max-width:700px" class="form-control" >
<option ng-repeat="user in (c.data.groupUsers | filter: {'groupName':groupSelectedValue}) track by $index" value="user.name">{{user.name}}</option>
</select>
</div>
</div>
<br/>
<div id="commentsSection" >
<div class="">
<span ng-hide="c.data.incidentData[0].incidentStatus == 'Closed'">
<b>Comments:</b> <textarea id="comments" class="form-control" ng-model="comments"> </textarea> <br/>
</span>
</div>
<br/>
<div class="">
<b>Comments History: </b>
<table class="table table-responsive">
<thead>
<tr>
<th>Comment </th>
<th>Entered Date </th>
<th>Entered By </th>
</tr>
</thead>
<tbody>
<tr ng-repeat="text in c.data.commentshistory track by $index">
<td>{{text.comment}}</td>
<td>{{text.enteredDate}}</td>
<td>{{text.enteredBy}}</td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-primary" ng-click="execute()">Execute</button>
<input type="hidden" id="sysId" value="{{sysId}}">
</div>
</div>
</div> <!-- End of Section3 -->
</div>
</div>
</div>
</div>
</div> <!-- End of Container -->
</div> <!--End of Panel Group -->
</div>
</div>
</div>
Angular JS Code:
(function()
{
"use strict";
var app=angular.module('indicatorModal',[]);
app.controller('incidentSummaryCtrl',['$scope',function($scope)
{
$scope.updateSelectedCoa=function()
{
//get Values from Form
var selectedCoa=jQuery("#sel1 option:selected").text();
var sendEmailUpdateToReporter=jQuery("#sendEmailUpdateToReporter").is(":checked");
var notifyIsp=jQuery("#notifyIsp").is(":checked");
var notifyDomainRegistrar=jQuery("#notifyDomainRegistrar").is(":checked");
var sendEmailReceipt=jQuery("#sendEmailReceipt").is(":checked");
var setStatusOfTicketToResolved=jQuery("#setStatusOfTicketToResolved").is(":checked");
var notifyProduction=jQuery("#notifyProduction").is(":checked");
var assignToNextTier=jQuery("#assignToNextTier").is(":checked");
var assignToGroup=jQuery("#assignToGroup").is(":checked");
var resolveAndCloseTicket=jQuery("#resolveAndCloseTicket").is(":checked");
var sysId=jQuery("#sysId").val();
var gr=new GlideRecord('x_19668_halo_incident');
gr.addQuery('sys_id',sysId);
gr.query(callbackFunction);
function callbackFunction(gr)
{
if(gr.next())
{
$scope.updateSelectedSysIdOfCoa(selectedCoa,sysId);
gr.send_email_update_to_reporter=sendEmailUpdateToReporter;
gr.notify_isp=notifyIsp;
gr.send_email_receipt_to_reporter=sendEmailReceipt;
gr.set_status_to_resolved=setStatusOfTicketToResolved;
gr.notify_production=notifyProduction;
gr.notify_domain_registrar=notifyDomainRegistrar;
gr.assign_to_tier=assignToNextTier;
gr.assign_to_group=assignToGroup;
gr.resolve_and_close_the_ticket=resolveAndCloseTicket;
gr.update();
}
}
};
$scope.updateSelectedSysIdOfCoa=function(selectedCoa,sysId)
{
var selectedCoaSysId='';
var gr1=new GlideRecord('x_19668_halo_selcted_ticket_course_of_action');
gr1.addQuery('incident_id',sysId);
gr1.query(callbackFunction2);
function callbackFunction2(gr1)
{
if(gr1.next())
{
var gr2=new GlideRecord('x_19668_halo_courseofactions');
gr2.addQuery('ticket_coa_name',selectedCoa);
gr2.query();
if(gr2.next())
{
selectedCoaSysId=gr2.sys_id+'';
}
gr1.ticket_coa_selected_id=selectedCoaSysId;
gr1.update();
}
}
};
$scope.passSysId=function(indicatorSysId,indicatorType)
{
var ipIndicatorsData = JSON.parse(sessionStorage.getItem('ipIndicatorsData'));
var domainIndicatorsData = JSON.parse(sessionStorage.getItem('domainIndicatorsData'));
var hashCodeIndicatorsData = JSON.parse(sessionStorage.getItem('hashCodeIndicatorsData'));
if(indicatorType == 'IP Address')
{
for(var indicator in ipIndicatorsData )
{
if(ipIndicatorsData[indicator].sysId == indicatorSysId)
{
jQuery("#indicatorId").text(ipIndicatorsData[indicator].indicatorId);
jQuery("#indicatorStatus").text(ipIndicatorsData[indicator].indicatorStatus);
jQuery("#indicatorType").text(ipIndicatorsData[indicator].indicatorType);
jQuery("#urgencyRanking").text(ipIndicatorsData[indicator].urgencyRanking);
jQuery("#completedEnrichCount").text(ipIndicatorsData[indicator].completedEnrichCount);
jQuery("#enrichStartTimestamp").text(ipIndicatorsData[indicator].enrichStartTimestamp);
jQuery("#enrichEndTimestamp").text(ipIndicatorsData[indicator].enrichEndTimestamp);
jQuery("#indicatorText").text(ipIndicatorsData[indicator].indicatorText);
$("#indicatorLink").attr("href", "https://dev21310.service-now.com/haloportal/?id=potential_indicator_summary&indicator_id="+indicatorSysId);
}
}
}
else if(indicatorType == 'Full Qualified Domain Name (FQDN)')
{
for(var indicator in domainIndicatorsData )
{
if(domainIndicatorsData[indicator].sysId == indicatorSysId)
{
jQuery("#indicatorId").text(domainIndicatorsData[indicator].indicatorId);
jQuery("#indicatorStatus").text(domainIndicatorsData[indicator].indicatorStatus);
jQuery("#indicatorType").text(domainIndicatorsData[indicator].indicatorType);
jQuery("#urgencyRanking").text(domainIndicatorsData[indicator].urgencyRanking);
jQuery("#completedEnrichCount").text(domainIndicatorsData[indicator].completedEnrichCount);
jQuery("#enrichStartTimestamp").text(domainIndicatorsData[indicator].enrichStartTimestamp);
jQuery("#enrichEndTimestamp").text(domainIndicatorsData[indicator].enrichEndTimestamp);
jQuery("#indicatorText").text(domainIndicatorsData[indicator].indicatorText);
jQuery("#indicatorLink").attr("href", "https://dev21310.service-now.com/haloportal/?id=potential_indicator_summary&indicator_id="+indicatorSysId);
}
}
}
else if(indicatorType == 'Hash Code')
{
for(var indicator in hashCodeIndicatorsData )
{
if(hashCodeIndicatorsData[indicator].sysId == indicatorSysId)
{
jQuery("#indicatorId").text(hashCodeIndicatorsData[indicator].indicatorId);
jQuery("#indicatorStatus").text(hashCodeIndicatorsData[indicator].indicatorStatus);
jQuery("#indicatorType").text(hashCodeIndicatorsData[indicator].indicatorType);
jQuery("#urgencyRanking").text(hashCodeIndicatorsData[indicator].urgencyRanking);
jQuery("#completedEnrichCount").text(hashCodeIndicatorsData[indicator].completedEnrichCount);
jQuery("#enrichStartTimestamp").text(hashCodeIndicatorsData[indicator].enrichStartTimestamp);
jQuery("#enrichEndTimestamp").text(hashCodeIndicatorsData[indicator].enrichEndTimestamp);
jQuery("#indicatorText").text(hashCodeIndicatorsData[indicator].indicatorText);
$("#indicatorLink").attr("href", "https://dev21310.service-now.com/haloportal/?id=potential_indicator_summary&indicator_id="+indicatorSysId);
}
}
}
};
}]);
})();
I would suggest you to use Angular UI instead of bootstrap
https://angular-ui.github.io/bootstrap/
Related
Am new to angularjs, i need to http post the dynamic form data to an API.
app.js
$scope.contacts = [
{ 'cpName':'',
'cpDesignation':'' ,
'cpDept': '',
'cpEmail': '',
'cpMobile':''
}
];
$scope.addRow = function(){
$scope.contacts.push({ 'cpName':$scope.cpName, 'cpDesignation': $scope.cpDesignation, 'cpDept':$scope.cpDept, 'cpEmail':$scope.cpEmail, 'cpMobile':$scope.cpMobile});
$scope.cpName='';
$scope.cpDesignation='';
$scope.cpDept='';
$scope.cpEmail='';
$scope.cpMobile='';
};
contact form
<form name="myform" role="form" ng-submit="addRow()">
<div class="row" ng-class="{true: 'error'}[submitted && myform.cpEmail.$invalid]">
<div class="form-group">
<label class="col-md-2 control-label">CONTACT PERSON</label>
<div class="col-md-4">
<input type="text" class="form-control" name="cpName"
ng-model="cpName" />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">DESIGNATION</label>
<div class="col-md-4">
<input type="text" class="form-control" name="cpDesignation"
ng-model="cpDesignation" />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">DEPARTMENT</label>
<div class="col-md-4">
<input type="text" class="form-control" name="cpDept"
ng-model="cpDept" />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">EMAIL*</label>
<div class="col-md-4">
<input type="email" class="form-control" name="cpEmail"
ng-model="cpEmail" />
<span style="color:red" ng-show="myform.cpEmail.$dirty && myform.cpEmail.$invalid">
<span ng-show="myform.cpEmail.$error.required">Email is required.</span>
<span ng-show="myform.cpEmail.$error.email">Invalid email address.</span>
</span>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">MOBILE</label>
<div class="col-md-4">
<input type="number" class="form-control" name="cpMobile"
ng-model="cpMobile" />
</div>
</div>
<div class="form-group">
<div style="padding-left:110px">
<input type="submit" value="Add" class="btn btn-primary"/>
</div>
</div>
</div>
</form>
<table>
<tr>
<th>CONTACT PERSON</th>
<th>DESIGNATION</th>
<th>DEPARTMENT</th>
<th>EMAIL</th>
<th>Mobile</th>
</tr>
<tr ng-repeat="contact in contacts">
<td>{{contact.cpName}} </td>
<td>{{contact.cpDesignation}} </td>
<td>{{contact.cpDept}} </td>
<td>{{contact.cpEmail}} </td>
<td>{{contact.cpMobile}} </td>
</tr>
</table>
I know how to handle a single form data but not dynamic data.. Any help will be appreciated.
Thank you
Use ng-repeat over the rows.. So, in starting your $scope.contacts has 1 row and hence it will show one row in html.. Now push new object to $scope.contacts and then 2 rows will come in UI.
So, now just by pushing empty object to $scope.contacts you can get any number of rows.
Don't worry about the data every row will maintain its own data in the $scope.contacts array .. and at last just send this object to server. So, now you have dynamic rows.
Define your form like this
<div class="row" ng-repeat="contact in contacts">
<div class="form-group">
<label class="col-md-2 control-label">CONTACT PERSON</label>
<div class="col-md-4">
<input type="text" class="form-control" name="cpName"
ng-model="contact.cpName" />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">DESIGNATION</label>
<div class="col-md-4">
<input type="text" class="form-control" name="cpDesignation"
ng-model="contact.cpDesignation" />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">DEPARTMENT</label>
<div class="col-md-4">
<input type="text" class="form-control" name="cpDept"
ng-model="contact.cpDept" />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">EMAIL*</label>
<div class="col-md-4">
<input type="email" class="form-control" name="cpEmail"
ng-model="contact.cpEmail" />
<span style="color:red" ng-show="myform.cpEmail.$dirty && myform.cpEmail.$invalid">
<span ng-show="myform.cpEmail.$error.required">Email is required.</span>
<span ng-show="myform.cpEmail.$error.email">Invalid email address.</span>
</span>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">MOBILE</label>
<div class="col-md-4">
<input type="number" class="form-control" name="cpMobile"
ng-model="contact.cpMobile" />
</div>
</div>
<div class="form-group">
<div style="padding-left:110px">
<input type="submit" value="Add" class="btn btn-primary"/>
</div>
</div>
</div>
<input type="button" value="Add" class="btn btn-primary" ng-click="upload()"/>
<table>
<tr>
<th>CONTACT PERSON</th>
<th>DESIGNATION</th>
<th>DEPARTMENT</th>
<th>EMAIL</th>
<th>Mobile</th>
</tr>
<tr ng-repeat="contact in contacts">
<td>{{contact.cpName}} </td>
<td>{{contact.cpDesignation}} </td>
<td>{{contact.cpDept}} </td>
<td>{{contact.cpEmail}} </td>
<td>{{contact.cpMobile}} </td>
</tr>
</table>
Here's your controller code
$scope.contacts = [{}];
$scope.upload = function(){
//api call
}
$scope.addRow = function(){
$scope.contacts.push({});
};
I am trying to display a table with data from an array in the controller. The html has a few input fields and on clicking submit I store the values in the input fields to the array. I then want to display the values in the table. I use ng-repeat on the tr.
I want the table to refresh and show the nwe data in the array. I am new to angularjs and I think the table should automatically show the new data because of ng-repeat. I'm not sure. If not, how do I refresh the table to show the new values.
But I think the problem is not that, because I added a few values to the array before pushing from the input fields, but the table still doesn't show my hard-coded array data.
The html(the table with ng-repeat is at the bottom and ng-controller at the top ):
<div class="content rows" ng-controller="mainController" >
<div class="navigationClass col-md-2"> <!-- Navigation DIv-->
<ul class="navColor nav nav-pills nav-stacked">
<li ><a style="color:#ffffff" href="#">Masters</a></li>
<li >Transactions</li>
<li ><a style="color:#ffffff" href="#">Reports</a></li>
<li ><a style="color:#ffffff" href="#">Devices</a></li>
<li class="active"><a style="color:#ffffff" href="#">Employees</a></li>
<li ><a style="color:#ffffff" href="#">Dashboard</a></li>
<li ><a style="color:#ffffff" href="#">Vendors</a></li>
</ul>
</div>
<div class="middle col-md-9 borderClass">
<div class="middle-header borderClass" style="padding-top:15px;padding-bottom:5px;">
<p style="text-align:center;color:#ffffff;">
Employee Registeration
</p>
</div>
<div class="">
<div class="createNewEmployee row" style="padding:5px;">
<div class="emptyDiv col-md-1"></div>
<div class="col-md-4">
<label class="marginClass" for="empId">Enter Employee ID</label>
<input ng-model="employeeID" type="text" id="empId" class="form-control marginClass" placeholder="Employee ID" name="">
<label for="empName" class="marginClass">Enter Employee name</label>
<input ng-model="employeeName" type="text" class="form-control marginClass" placeholder="Employee name" name="">
<label for="empCard" class="marginClass">Enter employee card number</label>
<input ng-model="employeeCardNumber" type="text" id="empCard" class="form-control marginClass" placeholder="Card number" name="">
<label for="doj" class="marginClass">Select employee DOJ</label>
<input ng-model="scopeDoj" type="text" id="doj" class="form-control marginClass" placeholder="DOJ" name="">
</div>
<div class="emptyDiv col-md-1"></div>
<div class="col-md-4">
<div class="form-group">
<label class="marginClass" for="categoryDropdown">Select category</label>
<select ng-model="employeeCategory" class="form-control marginClass" id="categoryDropdown">
<option>Company employee</option>
<option>Contract workman</option>
<option>Manager</option>
</select>
</div>
<div class="form-group">
<label class="marginClass" for="departmentDropdown">Select deparment</label>
<select ng-model="employeeDepartment" class="form-control marginClass" id="departmentDropdown">
<option>Pulp mill(Operation)</option>
<option>Stock preparation</option>
<option>Paper machine(Operation)</option>
<option>Finishing house</option>
<option>Paper machine(O)-V</option>
<option>SFT Street-C</option>
</select>
</div>
<div class="[ form-group ]" style="margin:5px; margin-top:25px;">
<input type="checkbox"
ng-model="activeOrInactive"
ng-true-value="'active'"
ng-false-value="'inactive'"
name="fancy-checkbox-default" id="activeID" autocomplete="off" />
<div class="[ btn-group ]">
<label class="" for="activeID">
Employee active
</label>
</div>
</div>
<div class="[ form-group ]" style="margin:5px; margin-top:25px;">
<input type="checkbox"
ng-model = "fingerprintActiveOrInactive"
ng-true-value="'fingeractive'"
ng-false-value="'fingerinactive'"
style="" name="fancy-checkbox-default" id="fingerprintActiveID" autocomplete="off" />
<div class="[ btn-group ]">
<label class="" for="fingerprintActiveID">
Fingerprint bio status active
</label>
</div>
</div>
</div>
<div class="emptyDiv col-md-2">
</div>
</div>
<p style="text-align:center"><button ng-click="addNewEmployee()" class="btn btn-primary">Submit</button></p>
</div>
<form class="form-inline" style="margin:20px;">
<div class="searchEmployee">
<div class="form-group">
<p>
<label class="marginClass" for="searchBox">Search employee</label>
<input id="searchBox" type="text" class="form-control" placeholder="Type here to search" name="">
</p>
</div>
</div>
</form>
<div class = "theTable" style="border:1px thin #ff0000;">
<table class="table table-hover table-bordered" style="margin-bottom:1px;">
<thead>
<th>Employee ID</th>
<th>Employee name</th>
<th>Card number</th>
<th>DOJ</th>
<th>Department</th>
<th>Category</th>
<th>Status</th>
<th>Edit/Delete</th>
</thead>
<tbody>
<tr ng-repeat="employee in newEmployeeArray">
<td>{{employee.empid}}</td>
<td>{{employee.empname}}</td>
<td>{{employee.empcardnumber}}</td>
<td>{{employee.doj}}</td>
<td>{{employee.empcategory}}</td>
<td>{{employee.empdepartment}}</td>
<td>{{employee.empactive}}</td>
<td>{{employee.empfingerprint}}</td>
<td><a title="Edit" href="#" style="text-align:center;text-decoration:none">
<span class="glyphicon glyphicon-pencil"></span></a><a title="Edit" href="#">
<span title="Delete" class="glyphicon glyphicon-trash"></span></a></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
The controller:
var app = angular.module('itc-app', ['ngRoute']);
app.controller('mainController',function($scope,$route,$timeout){
$scope.employeeID="";
$scope.employeeName="";
$scope.employeeCardNumber="";
$scope.scopeDoj="";
$scope.employeeCategory="Company employee";
$scope.employeeDepartment="Pulp mill(Operation)";
$scope.activeOrInactive="inactive";
$scope.fingerprintActiveOrInactive = "fingerinactive";
// $scope.newEmployeeScopeArray;
var newEmployeeArray = [
{
empid:'a',empname:'a',empcardnumber:'',doj:'',
empcategory:'',empdepartment:'',empactive:'',
empdepartment:'',empactive:'',empfingerprint:'',
empty:''
}
];
$scope.addNewEmployee = function(){
$timeout(function(){
newEmployeeArray.push({
empid:$scope.employeeID,
empname:$scope.employeeName,
empcardnumber:$scope.employeeCardNumber,
doj:$scope.scopeDoj,
empcategory:$scope.employeeCategory,
empdepartment:$scope.employeeDepartment,
empactive:$scope.activeOrInactive,
empfingerprint:$scope.fingerprintActiveOrInactive,
empty:''
});
// $route.reload();
$scope.employeeID="";
$scope.employeeName="";
$scope.employeeCardNumber="";
$scope.scopeDoj="";
$scope.activeOrInactive="inactive";
$scope.fingerprintActiveOrInactive = "fingerinactive";
console.log(newEmployeeArray);
},1000);
}
})
You just forgot to add newEmployeeArrayto your controllers $scope. When you do that, than pushing a new entry to that array will automatically update your view via ng-repeat.
newEmplyoeeArray is not visible from the $scope. You need to write
$scope.newEmployeeArray = [
{
empid:'a',empname:'a',empcardnumber:'',doj:'',
empcategory:'',empdepartment:'',empactive:'',
empdepartment:'',empactive:'',empfingerprint:'',
empty:''
}
];
instead of var newEmployeeArray.
Two things:
1) Please use the $scope for newEmployeeArray ($scope.newEmployeearray = .....)
Only the variable in the scope are watched for changes. That's the reason your view is not getting updated when the array is updated
2) You don't need to put the newEmployeeArray.push... inside the $timeout. $timeout would wait for the cycle to be completed and then push which would again change the scope and start a new cycle. This would hamper the performance.
i want that no body can save form without providing a name and here is my Html code ..what i am doing wrong i dont know ..i have checked many solutions please give me a reason...i want to know that how i will provide front-end validation
<div class="vbox wrapper" ng-controller="CalendarAddController">
<form id ="frmType" name="frmType" class="form-horizontal form-validation" novalidate method="get">
<div class="wrapper-v b-b col-lg-8 col-md-9 col-sm-10 col-xs-12" style="padding-bottom:5px;">
<div class="btn-toolbar pull-right ">
<a ui-sref="admin.calendar.entity" class="btn btn-xs btn-default">
Cancel
</a>
<a class="btn btn-xs btn-primary " ng-click="frmType.$valid && save()">Save</a>
</div>
<div class="h4 text-black">Add Calendar</div>
</div>
<h1> </h1>
<div class="wrapper-v col-lg-8 col-md-9 col-sm-10 col-xs-12" style="padding-bottom:5px;">
<div class="btn-toolbar pull-right">
</div>
<h4 class="wrapper text-muted">Calendar</h4>
</div>
<div class="wrapper-md" style="clear:both;">
<div class="form-group">
<label class="col-sm-2 control-label ">Name</label>
<div class="col-sm-8 col-lg-6">
<input type="text" name="name" ng-model="calendar.name"
placeholder="Enter calendar name" ng-minlength="1" ng-maxlength="15" class="form-control" ng-required="true" >
<span class="error code">{{errMsg}}</span>
<p class="help-block error-pattern">
Must start with a letter, may contain alphabets, digits and underscore.
</p>
<p class="error error-minlength">
Must be at least 1 character long.
</p>
<p class="error error-maxlength">
Length of "Name" field must not exceed 15 characters.
</p>
<span ng-show="frmType.name.$error.required && frmType.$submitted">Please provide role name</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Description</label>
<div class="col-sm-8 col-lg-6">
<input type="text" placeholder="Enter description" ng-maxlength="100"
ng-model="calendar.description" class="form-control" />
<p class="error error-maxlength">
Must not exceed 100 characters.
</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label ">Starting Day of Week</label>
<div class="col-sm-1 col-lg-1 dd-width">
<select name="startingDay" class="form-control" ng-model="calendar.weekStartDay">
<option value="1">Sunday</option>
<option value="2">Monday</option>
<option value="3">Tuesday</option>
<option value="4">Wednesday</option>
<option value="5">Thursday</option>
<option value="6">Friday</option>
<option value="7">Saturday</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Working days & Timings</label>
<div class="col-md-8 col-lg-6">
<h4 class="row text-bold">
<span class="col-md-12">
<span class="col-md-3">
Working Days
</span>
<span class="col-md-6 ">
Timing
</span>
</span>
</h4>
<div class="row text-bold" ng-repeat="calDay in calDays" >
<div class="col-md-12">
<div class="col-md-3">
<div class="checkbox">
<label class="i-checks i-checks-xs ">
<input type="checkbox" checklist-model="calendar.workingDays" ng-model="calDay.enabled"
checklist-value="calDay.dayNum" ng-change="selectDay(calDay.dayNum)" ><i></i>{{calDay.dayName}}
</label>
</div>
</div>
<div class="col-md-6">
{{timingDay=corrTimingDay(calDay.dayNum);""}}
<div class="row" >
<button class="btn btn-link" ng-disabled="!calDay.enabled" ng-click="open(timingDay)"
style="margin-bottom:-12px;">Add time block</button>
<span class="tooltipText"></span>
</div>
<div class="timing-chips" ng-repeat="timingBlock in timingDay.timingBlocks">
<span>{{intval(timingBlock.startTime/60)}}:{{makestr(timingBlock.startTime%60)}}
{{ampm(timingBlock.startTime)}} to
{{intval(timingBlock.endTime/60)}}:
{{makestr(timingBlock.endTime%60)}} {{ampm(timingBlock.endTime)}}</span>
<span class="hour">[{{totalTime(timingBlock.startTime,timingBlock.endTime)}} Hour]</span>
<i class="remove fa fa-remove no-padder" ng-click="timingDay.timingBlocks
.splice(timingDay.timingBlocks.indexOf(timingBlock),1)">
</i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="wrapper-md " style="clear:both;">
<div class="wrapper-v col-lg-8 col-md-9 col-sm-10 col-xs-12 " style="padding-bottom:5px;">
<h4 class="wrapper text-muted cls-space ">Holidays
<span class="btn-toolbar pull-right">
<a class="btn btn-xs btn-primary " ng-click="holidayOpen('lg')">Apply Holidays
</a> <input id="filter" type="text" ng-model="filterValue"
ng-change="filterTable()" placeholder="search"
class="form-control toolbar-item input-group w-xs inline m-l-xs" />
</span>
</h4>
</div>
<div class="col-lg-8 col-md-9 col-sm-10 col-xs-12 " style="padding-bottom:5px;">
<div class="wrapper-v-md" style="clear: both;">
<table datatable="ng" dt-options="dtOptionsHoliday" class="table table-striped clickable b-a table-condensed" >
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="holiday in calendarHolidays">
<td>{{holiday.name}}</td>
<td>{{holiday.description}}</td>
<td>{{holiday.date}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="wrapper-v col-lg-8 col-md-9 col-sm-10 col-xs-12 " style="padding-bottom:5px;">
<h4 class="wrapper text-muted cls-space">Exceptions
<span class="btn-toolbar pull-right">
<a class="btn btn-xs btn-primary " ng-click="exceptionOpen('lg')">Apply Exceptions
</a> <input id="filter" type="text" ng-model="filterValue"
ng-change="filterTable()" placeholder="search"
class="form-control toolbar-item input-group w-xs inline m-l-xs" />
</span>
</h4>
</div>
<div class="col-lg-8 col-md-9 col-sm-10 col-xs-12 " style="padding-bottom:5px;">
<div class="wrapper-v-md table-space" style="clear: both;">
<table datatable="ng" dt-options="dtOptionsException" class="table table-striped clickable b-a table-condensed" >
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="exception in calendarExceptions">
<td>{{exception.name}}</td>
<td>{{exception.description}}</td>
<td>{{exception.date}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div></form>
<!-- <pre>{{calendar |json}}</pre> -->
</div>
Can you just use required and see if it helps?
<input type="text" name="name" required>
Just adding onto #thepio's answer while you do that
<input type="text" name="name" ng-model="calendar.name"
placeholder="Enter calendar name" required >
<input type="submit" ng-disabled="!frmType.$valid">
The last line will disable your submit button until user types something in it.
If you want to check for if all letters were words I suggest using ng-pattern.
An example of what I used in my code
<div class="form-group">
<label class="control-label">Executive Name</label>
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Executive Name" name="execName" ng-model="user.execName" ng-pattern="/^[A-z ]*$/" required />
<span class="error" ng-show="createForm.execName.$error.required && createForm.execName.$touched">required</span>
<span class="error" ng-show="createForm.execName.$error.pattern && createForm.execName.$dirty">Must start with a letter, and contain letters only.</span>
</div>
you can use ng-message validation like:
<form name="form" validate>
<input id="name" name="name" md-maxlength="25"
ng-model="name" required autocomplete="false">
<div ng-messages="form.name.$error">
<div ng-message="required">Name field can not empty</div>
</div>
</form>
here if the full document about this.
I am new to Laravel and Angularjs. I would like some help on how to go about this.
Angular controller function
var loadTables = function(){
tableService.all(1,20)
.success(function(response){
console.log(response);
$scope.tables = response.data;
$scope.towns=response.town;
$scope.countrys=response.country;
$scope.package_lists=response.package_list;
$scope.categories=response.categories;
Laravel
$id = Auth::user()->id;
$packages = User::find($id)->packages;
//$packages=$packages->paginate(Input::get('perPage'))->toArray();
$countries = Country::lists('name', 'id');
$towns = Town::lists('name', 'id');
$categories = Category::lists('name', 'id');
$package_list=$packages->lists('name','id');
$packages->load('country');
return (['data'=>$packages,'town'=>$towns, 'categories'=>$categories, 'package_list'=>$package_list]);
View
<option ng-repeat="country in countrys" value="#{{country.id}}">#{{country.name}}</option>
1.The country values are not displayed in the view. how do i go about this.
<div ng-controller="tableController">
<a class="add-link btn btn-success" ng-click="toggleForm()" ng- hide="showForm">Add Packages</a>
<table class="table table-striped breathe" ng-hide="showForm">
<thead>
<tr><th>Name</th><th>About</th><th>status</th><th>Image</th> <th>Action</th></tr>
</thead>
<tbody>
<tr ng-repeat="table in tables">
<td>#{{table.name}}</td>
<td>#{{table.short_description}}</td>
<td>#{{table.status}}</td>
<td><img width="120" heigth="72" ng- src="#{{getImageSource(table.image)}}"/></td>
<td>
<button class="btn btn-sm btn-warning" ng- click="editTable(table.id)">Edit</button>
<button class="btn btn-sm btn-danger" ng- click="deleteTable(table.id, currentPage, $index)">Delete</button>
</td></tr>
</tbody>
</table>
<ul class="pagination" ng-hide="showForm">
<li ng-class="{'disabled':currentPage==1}"><a ng- click="loadFirstPage()">«</a></li>
<li ng-repeat="page in pages" ng-class="{'active':page==currentPage}"><a ng-click="loadNthPage(page)">#{{page}}</a></li>
<li ng-class="{'disabled':currentPage==lastPage}"><a ng-click="loadLastPage()">»</a></li>
</ul>
<form name="tablesForm" ng-show="showForm" class="col-md-4" enctype="multipart/form-data">
<div class="form-group">
Name<input type="text" name="number" ng-model="newName" class="form- control" required>
<em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em>
</div>
<div class="form-group">
Avarage Price<input type="text" name="seats" ng-model="newPrice" class="form-control" required>
<em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em>
</div>
<div class="form-group">
Short Description<input type="text" name="position" ng- model="newShort_description" class="form-control">
</div>
<div class="form-group">
Description<input type="textarea" name="description" ng-model="newDescription" class="form-control">
</div>
<div class="form-group">
Category<select type="text" id="category" ng-model="newCategory" class="form-control" required>
<option ng-repeat="category in categories" value="#{{category.id}}">#{{category.id}}</option>
</select>
<em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em>
</div>
<div class="form-group">
Country<select type="text" name="country" ng-model="newCountry" class="form-control" required>
<option ng-repeat="country in countrys" value="#{{country.id}}">#{{country.name}}</option>
</select>
<em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em>
</div>
<div class="form-group">
Town<select type="text" name="town" ng-model="newTown" class="form-control" required>
<option ng-repeat="town in towns" value="#{{town.id}}">#{{town.name}}</option>
</select>
<em class="muted" ng-show="tablesForm.available.$pristine && tablesForm.available.$invalid">Required</em>
</div>
<div class="form-group">
<img width="120" height="82" ng-src="#{{newThumbnail}}" ng-show="showEdit" style="display: block;" />
Image<input type="file" name="thumbnail" ng-file-select="onFileSelect($files)">
</div>
<div class="form-group">
<button class="btn btn-primary" ng-hide="showEdit" ng-click="tablesForm.$valid &&addNewTable(newNumber,newSeats,newPosition,newDescription,newAvailable, currentPage)">Add new table</button>
<button class="btn btn-primary" ng-show="showEdit" ng-click="tablesForm.$valid && updateTable(tableId, newNumber,newSeats,newPosition,newDescription,newAvailable)">Update table</button>
<button class="btn btn-danger" ng-show="showForm" ng-click="toggleForm()">Cancel</button>
</div>
You're not returning countries on the response list
Try the below code:
return (['data'=>$packages,'town'=>$towns, 'country':$countries, 'categories'=>$categories, 'package_list'=>$package_list]);
Edit: as per your comments, it shows that you're returning your data as objects, not arrays. For Angular to iterate through that data, it should be stored in an array.
I am using backbone to populate the table and then be able to edit the contents using modals implemented in bootstrap.
The table populates very well but on clicking edit on the modal, all field contain data of the first entry only
Here is the code,
<tbody>
<% users.each(function(user){ %>
<tr>
<td>
<%= user.get("first_name") %>
</td>
<td><%= user.get("last_name") %></td>
<td><%= user.get("gender") %></td>
<td >
24 years
</td>
<td >
<%= user.get("email") %>
</td>
<td class="hidden-480">
<%= user.get("phone_number")%>
</td>
<td class="hidden-480">
<%= user.get("role") %>
</td>
<td>
<div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
<a href="#modal-form" role="button" class="blue" data-toggle="modal">
<i class="icon-pencil bigger-130" id="user_edit" ></i>
</a>
<a class="red" href="#">
<i class="icon-trash bigger-130" id="user_delete" ></i>
</a>
</div>
</td>
</tr>
<div id="modal-form" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="blue bigger">Edit User</h4>
</div>
<div class="modal-body overflow-visible">
<div class="row">
<div class="col-xs-12">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> First Name </label>
<div class="col-sm-9">
<input type="text" id="user_first_name" value=<%= user.get("first_name")%> class="col-xs-10 col-sm-10" />
</div>
</div><br>
<div class="space-4"></div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Last Name </label>
<div class="col-sm-9">
<input type="text" id="user_last_name" value=<%= user.get("last_name")%> class="col-xs-10 col-sm-10" />
</div>
</div> <br>
<div class="space-4"></div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Date of Birth </label>
<div class="col-sm-9">
<input type="text" id="user_date_of_birth" value=<%= user.get("date_of_birth")%> class="col-xs-10 col-sm-10" />
</div>
</div><br>
<div class="space-4"></div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Gender </label>
<div class="col-sm-9">
<select id="user_gender" class="col-xs-10 col-sm-10 ">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div><br>
<div class="space-4"></div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> Phone Number </label>
<div class="col-sm-9">
<input type="text" id="user_phone_number" value=<%= user.get("phone_number")%> class="col-xs-10 col-sm-10" />
</div>
</div><br>
<div class="space-4"></div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> E-mail Address </label>
<div class="col-sm-9">
<input type="text" id="user_email" value=<%= user.get("email")%> class="col-xs-10 col-sm-10" />
</div>
</div><br>
<div class="space-4"></div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-2">
Password
</label>
<div class="col-sm-9">
<input id="user_password" class="col-xs-10 col-sm-10" type="password">
</div>
</div><br>
<div class="space-4"></div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-2">
Confirm Password
</label>
<div class="col-sm-9">
<input id="password_confirmation" class="col-xs-10 col-sm-10" type="password">
</div>
</div> <br>
<div class="clearfix form-actions">
<div class="col-md-offset-3 col-md-9">
<button class="btn btn-info" type="button" id="user_submit">
<i class="icon-ok bigger-110"></i>
Submit
</button>
<button class="btn" type="reset">
<i class="icon-undo bigger-110"></i>
Reset
</button>
</div>
</div>
<div class="hr hr-24"></div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<% }); %>
</tbody>
In your loop you are assigning an ID to the modal and this is giving them all the same IDs. Maybe the bootstrap JS is only showing the first one that it finds which is why you see the same one every time. Maybe you if you appended the ID of the user or something unique to the ID of the modal this would work.
For Example:
<div id="modal-form" class="modal" tabindex="-1">
and
<a href="#modal-form" role="button" class="blue" data-toggle="modal">
could be changed to:
<div id="modal-form-<%= user.get('id') %>" class="modal" tabindex="-1">
and
<a href="#modal-form-<%= user.get('id') %>" role="button" class="blue" data-toggle="modal">