angular custom directive inside ng-repeat not perform on second load - angularjs

(function() {
'use strict';
angular.module('app.core').directive('abrRecText', abrRecText);
function abrRecText() {
return {
restrict: 'E',
scope: {
details: '='
},
controller: recTextController,
controllerAs: 'vm',
templateUrl: 'app/abr/abr-directives/abr-templates/abr-rec-text.html'
};
}
})();
Above code is Custom Directive and below view Section
Inside li i'm getting event on the second load, but directive not getting
Onclick of page number calling api and getting response.
<div class="abr-pagination">
<div class="abr-pagination-wrap">
<div class="abr-pagination-split pull-left">
<paging class="small" page="vm.filterData.paging.currentPageNumber" page-size="vm.filterData.paging.pageSize" total="total" ul-class="pagination rmapp" active-class="active" disabled-class="disabled" adjacent="1" app-name="rm" dots="..." show-prev-next="true" show-first-last="true" hide-if-empty="true" paging-action="vm.pageChanged(page)">
</paging>
</div>
</div>
<div class="col-md-12 nopadding table-show-page pagination">
<div class="col-md-2 nopadding abr-pagination-goto goto-page table-go-to pull-left">
<lable> Go to </lable>
<input type="number" aria-invalid="false" ng-model="vm.filterData.paging.currentPageNumber" ng-change="vm.getTableData()" />
</div>
<div class="col-md-4 nopadding abr-pagination-perpage pagination-per-page table-entries pull-left">
<lable class="pull-left">Entries per page </lable>
<div class="pull-left pagination-select-container">
<select ng-model="vm.filterData.paging.pageSize" ng-options="item for item in vm.selectitems" ng-change="vm.getTableData()"></select>
</div>
</div>
</div>
</div>
</div>
<ul>
<li class="inlineblock" ng-repeat="(key,event) in events.recommendationObj track by $index">
<div class="col-md-12 paddingfive">
<abr-rec-text details="[{'cogKey': 'rectext','cogValue': event.recommendedText },{'cogKey': 'startsAt','cogValue': event.startsAt }, {'cogKey': 'isStory','cogValue':false },{'cogKey': 'widgetMasterId','cogValue':events.widgetMasterId },{'cogKey': 'cardIcId','cogValue':event.cardIcId},{'cogKey': 'attrId','cogValue':attrId},{'cogKey': 'widgetId','cogValue':widgetId}]"></abr-rec-text>
</div>
</li>
</ul>
<div class="abr-pagination">
<div class="abr-pagination-wrap">
<div class="abr-pagination-split pull-left">
<paging class="small" page="vm.filterData.paging.currentPageNumber" page-size="vm.filterData.paging.pageSize" total="total" ul-class="pagination rmapp" active-class="active" disabled-class="disabled" adjacent="1" app-name="rm" dots="..." show-prev-next="true" show-first-last="true" hide-if-empty="true" paging-action="vm.pageChanged(page)">
</paging>
</div>
</div>
<div class="col-md-12 nopadding table-show-page pagination">
<div class="col-md-2 nopadding abr-pagination-goto goto-page table-go-to pull-left">
<lable> Go to </lable>
<input type="number" aria-invalid="false" ng-model="vm.filterData.paging.currentPageNumber" ng-change="vm.getTableData()" />
</div>
<div class="col-md-4 nopadding abr-pagination-perpage pagination-per-page table-entries pull-left">
<lable class="pull-left">Entries per page </lable>
<div class="pull-left pagination-select-container">
<select ng-model="vm.filterData.paging.pageSize" ng-options="item for item in vm.selectitems" ng-change="vm.getTableData()"></select>
</div>
</div>
</div>
</div>
</div>
Initially directive is loading, once I click on the second page of pagination button controller is perform and getting response also but the directive is not performing based on the second response.
Any ideas would be appreciated!

Related

Common ng-model value in ng-repeat

I am listing div using ng-repeat to in following manner and include form-template which is assigned. I have several form-template and want to include in following manner. They can have nested ng-repeat to include same template. So i am using "trackerWidgetData" variable in my template. its working fine but inner ng-repeat have different variable(dependWidgetData).
How to use common model value for form-template. If we are including it in nested ng-repeat.
<div class="listview-trckr-new clearfix" ng-repeat="trackerWidgetData in optionsList.inlineTemplates | filter:options.trackerSearchClient track by $index">
<div class="listview-trckr-new-top">
<div class="listview-trckr-new-left clearfix">
<h3>{{trackerWidgetData.trackerName}}</h3>
</div>
<div class="listview-trckr-new-right">
<div ng-if="trackerWidgetData.template" ng-include src="'/public/views/tracker-templates/'+trackerWidgetData.template"></div>
</div>
</div>
<div class="listview-trckr-new-btm" ng-if="trackerWidgetData.dependendTrackers && trackerWidgetData.dependendTrackers.length">
<div class="listview-trckr-new-top" ng-repeat="dependWidgetData in trackerWidgetData.dependendTrackers">
<div class="listview-trckr-new-left clearfix">
<h3>{{dependWidgetData.trackerName}}</h3>
</div>
<div class="listview-trckr-new-right">
<div ng-if="dependWidgetData.template" ng-include src="'/public/views/tracker-templates/'+dependWidgetData.template"></div>
</div>
</div>
</div>
</div>
I have many different type template like this.
<script type="text/ng-template" id="addManualContent.tpl">
<ng-form name="stepAddForm" novalidate >
<div class="new-weight-tracker">
<div class="weight-auto-fil-input">
<input type="text" name="value" ng-model="form[trackerWidgetData.uniqueFormId].trackerValue.values[0].value" />
<div class="new-trkr-select">
<select class="weight-selectbox" name="foodUnit" ng-model="form[trackerWidgetData.uniqueFormId].trackerValue.values[0].unitId" ng-options="opt.id as opt.unitName for opt in trackerWidgetData.unitType.units">
</select>
</div>
</div>
<div class="new-tracker-cale">
<adm-dtp ng-model='form[trackerWidgetData.uniqueFormId].trackerValue.dateTime' maxdate="{{optionsList.maxTimeStamp}}" options='{format: toUpperString(dateFormat) + "hh:mm", default: todayTimestamp, freezeInput:false}'>
<input name="date" ng-model="form[trackerWidgetData.uniqueFormId].trackerValue.dateTime" ng-click="initDTP(form[trackerWidgetData.uniqueFormId].trackerValue.dateTime)" type="text" ng-required="true" dtp-input>
<i aria-hidden="true" class="fa fa-calendar" ng-click="initDTP(form[trackerWidgetData.uniqueFormId].trackerValue.dateTime)" dtp-toggle></i>
</adm-dtp>
</div>
<div class="new-logit-btn">
<a ng-href="" ng-class="{'disable-anchor-btn': optionsList.inAddProcess}" ng-click="optionsList.inAddProcess ? null : addTrackerValue(stepAddForm, trackerWidgetData)" class="fill_button">Log It</a>
</div>
</div>
</ng-form>
</script>
The Question is How to pass model value to ng-template when including it?

Angularjs directive doesn't popup with individual selected row

I am trying to pass each scope.selectedLiability based on selection into popup modal from recordRecommendedLiabilityCash directive into detailViewRecommendedLiabilityCash directive on each click.
Here are the core function in recordRecommendedLiabilityCash.
scope.openDetailView = function (id) {
// console.log(scope.recommendedLiabilities[id]);
scope.selectedLiability = scope.recommendedLiabilities[id];
console.log(scope.selectedLiability);
if (!scope.detailViewFlag) {
scope.detailViewFlag = true;
}
};
Up to here everything is okay. In each click console.log(scope.selectedLiability); shows respective selected data. Now, I am trying to pass scope.selectedLiability into nested directive detailViewRecommendedLiabilityCash. However, only first or 0 index value popups in every click.
Picture for index 0
Picture for index 2
If you look carefully on images, we can see both data are same in both clicks. However, I need respective selected data in corresponding click.
Sorry for messed up code. This is not my own code. I am trying help my friend. I stuck here.
//recordRecommendedLiabilityCash directive
.directive('recordRecommendedLiabilityCash', function () {
return {
restrict: 'E',
templateUrl: 'cash/savings-liabilities/recommended-liability-accounts/record-recommended-liability.html',
scope: {
rlc: '=',
liabilities: '=',
listOfLumpSumSource: '=listOfLumpSumSource',
id: '=',
recommendedLiabilities: '='
},
link: function (scope, element, attrs) {
scope.detailViewFlag = false;
scope.removeRecommendedLiabilityRecordCash = function () {
if (scope.rlc.active) {
scope.rlc.active = false;
}
// To-Do: Refactor into reusable function
for (var i = 0; i < scope.liabilities.length; i++) {
if (scope.rlc.legacyId === scope.liabilities[i].id) {
if (!scope.liabilities[i].active) {
scope.liabilities[i].active = true;
}
}
}
};
scope.openDetailView = function (id) {
// console.log(scope.recommendedLiabilities[id]);
scope.selectedLiability = scope.recommendedLiabilities[id];
console.log(scope.selectedLiability);
if (!scope.detailViewFlag) {
scope.detailViewFlag = true;
}
};
}
};
})
//detailViewRecommendedLiabilityCash directive
.directive('detailViewRecommendedLiabilityCash', function () {
return {
restrict: 'E',
templateUrl: 'cash/savings-liabilities/recommended-liability-accounts/detail-view-recommended-liability.html',
scope: {
rlc: '=',
listOfLumpSumSource: '=listOfLumpSumSource',
detailViewFlag: '=',
recommendedLiabilities: '=',
id: '=id',
selectedLiability: '=selectedLiability'
},
link: function (scope, element, attrs) {
console.log(scope.selectedLiability);
scope.rlc.payment_amount = '';
scope.rlc.due_amount = scope.rlc.remainingBalance;
console.log(scope.listOfLumpSumSource);
scope.selectedLumpSumSource = null;
console.log(scope.selectedLumpSumSource);
console.log(scope.recommendedLiabilities, scope.id);
scope.lumpSumDataSource = [
{
"companyName": "FCB",
"productName": "Product1"
},
{
"companyName": "First Command",
"productName": "Product2"
},
{
"companyName": "Second Command",
"productName": "Product3"
}
];
//scope.lumpSumSource = scope.rlc.lumpSumSource;
console.log(scope.rlc.lumpSumSource);
//scope.lumpSumDataSource.push(scope.rlc.lumpSumSource);
// Intialize default variables
var defaultLumpSumObject = {'lumpSumSource': '', 'lumpSumAmount': '', 'remainingBalance': ''};
scope.lumpSumArray = [defaultLumpSumObject];
scope.exisitingAccountObj = {
monthlyPayment: scope.rlc.monthlyPayment
};
// Function to add lumpsum source
scope.addSource = function() {
scope.lumpSumArray.push(defaultLumpSumObject);
};
// Function to delete lumpsum source
scope.deleteSource = function(index) {
scope.lumpSumArray.splice(index,1);
};
scope.closeDetailView = function () {
if (scope.detailViewFlag) {
scope.detailViewFlag = false;
}
};
// When the user clicks anywhere outside of the modal, close it
element.on('click', function (e) {
var target = $(e.target);
if (!target.closest('.modal-content').length) {
scope.$evalAsync(scope.closeDetailView());
}
});
scope.saveRecommendedLiabilityAccount = function () {
scope.rlc.remainingBalance = scope.rlc.remainingBalance - scope.rlc.payment_amount;
scope.rlc.lumpSumAmount = scope.rlc.lumpSumAmount - scope.rlc.payment_amount;
console.log(scope.rlc.lumpSumAmount);
};
}
};
});
<!--recordRecommendedLiabilityCash template -->
<div class="Table-row">
<div class="Table-row-item" data-header="Company">
<a class="edit-view" ng-click="openDetailView(id)" data-toggle="modal" data-target="#{{'modal-detail-view-cash-rec-liability-' + rlc.id}}">{{ rlc.companyName }}</a>
</div>
<div>{{selectedLiability}}</div>
<div class="Table-row-item" data-header="Product">{{ rlc.productName }}{{rlc.id}}{{id}}</div>
<div class="Table-row-item" data-header="Liability Type">{{ rlc.liabilityType }}</div>
<div class="Table-row-item" data-header="Owner">{{ rlc.owner }}</div>
<div class="Table-row-item" data-header="Loan Balance">{{ rlc.remainingBalance | currency:"$":0 }}</div>
<!-- <div class="Table-row-item" data-header="Lump Sum">{{ rlc.LibtyLumpSumFundBal | currency:"$":0 }}</div>-->
<div class="Table-row-item" data-header="Monthly">{{ rlc.monthlyPayment | currency:"$":2 }}</div>
<div class="Table-row-item custom-select" data-header="Action">
<select id="action" name="action">
<option value="">I Want To …</option>
<option value="Retain">Retain</option>
<option value="Consolidate">Consolidate</option>
<option value="Pay-Off">Pay-Off</option>
<option value="Pay-Down">Pay-Down</option>
</select>
<div class="select__arrow"></div>
</div>
<!-- <div class="Table-row-item status" data-header="Status">
<div>{{ rlc.status }}</div>
<a class="close-button" ng-click="removeRecommendedLiabilityRecordCash()"></a>
</div>-->
</div>
<detail-view-recommended-liability-cash rlc="rlc" selected-liability="selectedLiability" recommended-liabilities="recommendedLiabilities" id="id" list-of-lump-sum-source="listOfLumpSumSource" detail-view-flag="detailViewFlag"></detail-view-recommended-liability-cash>
<!-- template for details view recommended liability-cash -->
<div class="modal fade" role="dialog" id="{{'modal-detail-view-cash-rec-liability-' + rlc.id}}">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<span class="close" data-dismiss="modal">×</span>
<h4>Savings - Liabilities <label class="pull-right">{{ rlc.remainingBalance }}</label></h4>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<label class="header-sub-label">Owner: <span>{{ rlc.owner }}</span></label>
<label class="header-sub-label pull-right">Loan Balance</label>
</div>
</div>
</div>
<form name="recommendedLiabilityForm" novalidate >
<div class="modal-body">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label class="control-label">Company</label>
<label class="control-value">{{ selectedLiability.companyName }}</label>
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<label class="control-label">Product</label>
<label class="control-value">{{ selectedLiability.productName }}</label>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<label class="control-label">Description</label>
<label class="control-value">{{ selectedLiability.description }}</label>
</div>
</div>
<div class="row display-row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label class="control-label">Liability Type</label>
<label class="control-value">{{ selectedLiability.liabilityType }}</label>
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<label class="control-label">Mortgage Type</label>
<label class="control-value">{{ selectedLiability.mortgageType }}</label>
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<label class="control-label">Interest Rate</label>
<label class="control-value">{{ selectedLiability.interestRate | currency:"$":2 }}%</label>
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<label class="control-label">Payment Type</label>
<label class="control-value">{{ selectedLiability.paymentType }}</label>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3">
<label class="control-label">Current Monthly Payment</label>
<label class="control-value">{{ selectedLiability.monthlyPayment }}</label>
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<label class="control-label">Payment Frequency</label>
<label class="control-value">{{ selectedLiability.paymentFrequency }}</label>
</div>
<div class="col-lg-6 col-md-6 col-sm-6">
<label class="control-label">Remaining Term</label><br>
<label class="control-label">Years</label><span> {{ rlc.remainingTermYears }} </span>
<label class="control-label">Months</label><span> {{ rlc.remainingTermMonths }} </span><br>
<label class="control-label">End Date:</label><span> {{ rlc.remainingTermEndDate | date:'yyyy-MM-dd' }} </span>
</div>
</div>
<hr />
<label class="heading">Funding</label>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 form-group">
<label for="monthlyFunding">Recommended Monthly Payment</label>
<input name="monthlyFunding" ng-model="exisitingAccountObj.monthlyPayment" class="form-control col-md-6 col-lg-6 col-sm-6" type="text" />
</div>
</div>
<label class="heading">Lump Sum</label>
<div class="row" ng-repeat="lumpSumData in lumpSumArray track by $index">
<div class="col-lg-3 col-md-3 col-sm-3 form-group">
<label for="source" class="control-label">Source</label>
<select name="source" ng-model="selectedLumpSumSource"
ng-options="lumpSumSource as lumpSumSource for lumpSumSource in listOfLumpSumSource"
class="form-control" ng-change="getLumpSumAmount(selectedLumpSumSource)"></select>
<!--<select name="source" ng-model="source" ng-options="source for source in lumpSumSource" class="form-control"></select>-->
</div>
<div class="col-lg-3 col-md-3 col-sm-3 form-group">
<label for="amount" class="control-label">Amount</label>
<input name="amount" ng-model="rlc.payment_amount" class="form-control" type="number" min="0" max="{{rlc.remainingBalance}}" required />
</div>
<div ng-messages="recommendedLiabilityForm.amount.$error" style="color:red">
<div ng-message="validationError">this is the error</div>
<div ng-message="required">Must have value</div>
<div ng-message="minlength">Must be 5 char length</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<label class="control-label">Remaining Balance</label>
<label class="control-value">{{selectedLiability.lumpSumAmount - selectedLiability.payment_amount | currency:"$":2}}</label>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 vertical-line">
<span class="glyphicon glyphicon-trash" ng-click="deleteSource($index)"></span>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 add-button-container">
<button type="button" class="btn btn-primary" ng-click="addSource()"><span class="glyphicon glyphicon-plus"></span><span class="add-more-button">Add Another Source</span></button>
</div>
</div>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">cancel</button>
<button type="submit" class="btn btn-primary" ng-click="saveRecommendedLiabilityAccount()">Save</button>
</div>
</div>
</div>
</div>
It is not clear with the code you pasted, but looks like you are creating N modals, one per each row:
<a class="edit-view" ng-click="openDetailView(id)" data-toggle="modal" data-target="#{{'modal-detail-view-cash-rec-liability-' + rlc.id}}">{{ rlc.companyName }}</a>
This link should open the modal that matches the same rc.id. This means you have N <detail-view-recommended-liability-cash/> directives, one per rc.id. Isn't it? If you did not generate the same amount of <detail-view-recommended-liability-cash/>, one per row, then you cannot identify the opening modal. Still, I think this is a bad idea, as unfortunately you have N modals, all pointing to the same scope.selectedLiability object. I'm not 100% sure, but if you mess something, can be the case that you're always seeing the last rendered modal. Also, bootstrap is plain JS + jQuery, and you're using Angular for the directive.
I think what is happening is that when you click for the first time, Angular is rendering all the modals pointing to the same object, but on the subsequent clicks the objects are not refreshed on the directives. Perhaps a $scope.$apply() can fix the bug?
Try to clean your code so you have only one modal, and make sure it is isolated as a directive, and before doing scope.detailViewFlag = true, make sure you cleaned everything before. In general, JS and Angular do not play well, and you need to abuse the use of scope.$apply() on the JS calls. That's why the angular directives for bootstrap isolates the modals passing a new object, a new controller, etc.
To sum up: you have a lot of modals on your code, one per row, pointing to the same object on the recordRecommendedLiabilityCash directive. When you click for the first time, all the modals are "filled", but on the second click you never cleaned the information from the modals, and Angular never refreshed the information. To fix this: use only one modal, and make sure you're cleaning the information before opening the modal.
90% sure that's your problem. Try to avoid modals by id, and control them manually on JS within Angular, and check when to execute the $apply().
Regards!

Taking user in put in a Controller Array

I am new with Angularjs. I want to take user input in my array of the controller
This is the html
<div class="col-md-6">
<div class="row text-center">
<div class="col-xs-6">
<h4> data A:</h4>
</div>
<div class="col-xs-6">
<h4><input type="text" class="form-control" ng-model="a"></h4>
</div>
</div>
<div class="row text-center">
<div class="col-xs-6">
<h4>data B:</h4>
</div>
<div class="col-xs-6">
<h4><input type="text" class="form-control" ng-model="b"></h4>
</div>
</div>
<div class="row btn-primary text-center" ng-click="showData()">
<i class="glyphicon glyphicon-folder-open" aria-hidden="true">
<h4>data</h4>
</i>
</div>
and the controller
$scope.infoSet =[
{
"key" : "data A",
"value" : $scope.a
},
{
"key" : "data B",
"value" : $scope.b
}];
$scope.showData = function () {
console.log($scope.infoSet);
console.log($scope.a);
console.log($scope.b);
}
How can i do that ? i have tried Difficulty with ng-model, ng-repeat, and inputs .
But i cant put the input in proper format with this. please help . thanks in advance
Remove $scope.a and $scope.b, and use
ng-model="infoSet[0].value"
and
ng-model="infoSet[1].value"
Or use ng-repeat
<div class="row text-center" ng-repeat="info in infoSet">
<div class="col-xs-6">
<h4>{{info.key}}</h4>
</div>
<div class="col-xs-6">
<h4><input type="text" class="form-control" ng-model="info.value"></h4>
</div>
</div>

how to validate two select boxes in angular js

this is my html form that have to use to get the details but when i use the required attribute in the select tag, only the first one is validated and not the second one or an other field after the select tag, for eg if i select option in the first select and click post project then there is no error about the validation, and if i dont select the data from the first select tag there is validation error popup saying that the field is required,
<form name="myForm" role="form" action="#">
<div class="well" style="margin-left:20px; margin-right:20px">
<div class="row" style="margin-left:5px; margin-right:5px">
<div class="col-lg-12">
<h4 style="color:darkblue">What type of project do you require?</h4>
</div>
</div>
<br>
<div class="row" style="margin-left:5px; margin-right:5px">
<div class="col-md-6 col-lg-6">
<select name="drop1" class="form-control" ng-model="project.match1">
<option value="">-- Select Category --</option>
<option ng-repeat="items in serviceCategory" value="{{items.ServiceCategoryId}}">{{items.ServiceCategoryName}}</option>
</select>
</div>
<div class="col-md-6 col-lg-6">
<select class="form-control" ng-model="project.match2" name="drop2">
<option value="">-- Select Sub Category --</option>
<option ng-repeat="a in service" ng-if="a.ServiceCategoryId==project.match1">
{{a.ServiceName}}
</option>
</select>
</div>
</div>
<br>
<div class="row" style="margin-left:5px; margin-right:5px">
<div class="col-md-12 col-lg-12">
<textarea ng-model="project.ServiceCategories" placeholder="Add Service Categories here" rows="3" style="resize:none; width:100%"></textarea>
</div>
</div>
</div>
<div class="well" style="margin-left:20px; margin-right:20px">
<div class="row" style="margin-left:5px; margin-right:5px">
<div class="col-md-12 col-lg-12 text-left">
<h4 style="color:darkblue">What is your Project about</h4>
</div>
</div>
<br>
<div class="row" style="margin-left:5px; margin-right:5px">
<div class="col-md-12 col-lg-12 text-left">
Describe your Project<br>
</div>
</div>
<div class="row" style="padding-top:10px; margin-left:5px; margin-right:5px">
<div class="col-md-12 col-lg-12">
<input type="text" ng-model="project.DescribeProject" style="width:100%">
</div>
</div>
<br>
<div class="row" style="margin-left:5px; margin-right:5px">
<div class="col-md-6 col-lg-6">
What is your Project about?
</div>
<div class="col-md-6 col-lg-6">
</div>
</div>
<div class="row" style="padding-top:10px; margin-left:5px; margin-right:5px">
<div class="col-md-12 col-lg-12">
<textarea ng-model="project.AboutProject" ng-trim="false" rows="3" cols="70" ng-maxlength="5000" style="resize:none; width:100%;"></textarea>
</div>
</div>
<br>
<div class="row" style="margin-left:5px; margin-right:5px">
<div class="col-md-12 col-lg-12">
Attach files
</div>
</div>
<div class="row" style="padding-top:10px; margin-left:5px; margin-right:5px">
<div class="col-md-12 col-lg-12">
<!--attach file code-->
<div style="height:30px; width:100%;">
</div>
</div>
</div>
<div class="row" style="margin-bottom:15px; margin-left:5px; margin-right:5px">
<div class="col-md-1 col-lg-1"></div>
<div class="col-md-10 col-lg-10">
<div class="text-right">
<button class="btn btn-default btn-primary" type="submit" ng-click="showData(project)">Post Project</button>
<button class="btn btn-default" data-dismiss="modal" aria-label="Close" style="color:black; border-color: #2e6da4">Close</button>
</div>
</div>
<div class="col-md-1 col-lg-1"></div>
</div>
</div>
</form>
The Script is
var app = angular.module("MyApp", []);
app.controller('MainCtrl', function ($scope, $http) {
$http.get('/JsonData/ServiceCategory.json').success(function (response) {
console.log("Service Category Connected");
$scope.serviceCategory = response;
});
$http.get('/JsonData/Service.json').success(function (res) {
console.log("Service Connected");
$scope.service = res;
});
$scope.showData = function (inputData) {
var Project = new Object();
Project.Category = inputData.match1;
Project.SubCategory = inputData.match2;
Project.ServiceCategories = inputData.ServiceCategories;
Project.Description = inputData.DescribeProject;
Project.AboutProject = inputData.AboutProject;
var ProjectJson = JSON.stringify(Project);
alert(ProjectJson);
}
});

Having issues sending scope to the template in AngularJS

MY issue is this:
When I request the data from the server this sent the data correctly but in LoginController after doing the validation I'm trying to populate the user's username and email but those variables are not being printed in the template. However if I just send those variables in a simple JSON such as $scope.details = [{ 'username':'Karman', 'username':'karman#mail.com'}]; it's working fine, what am I doing wrong? Is there some issue with ng-repeat directive?
Thanks in advance to whom can help me out with this issue.....
ps: I'm using sillex and ng-resource just in case
<body ng-controller="LoginController">
<div class="col-xs-3 details-user">
<div class="col-xs-1">
<img src="web/img/avatar.jpg" alt="..." class="img-circle">
</div>
<div class="col-xs-2">
<ul>
<li ng-repeat="detail in details">
{{detail.username}} -- {{detail.email}}
</li>
</ul>
</div>
</div>
Controller:
function LoginController($scope, Login) {
var currentResource;
$scope.login = function () {
Login.query({email: $scope.email}, function success(data){
$scope.details = data;
//$scope.details = [{ 'username':'Karman', 'username':'karman#mail.com'}];
});
}
}
Form:
<!-- Main DIV -->
<div id="login" class="login-main">
<div class="form-wrap">
<div class="form-header">
<i class="fa fa-user"></i>
</div>
<div class="form-main">
<form>
<div class="form-group">
<input ng-model="email" type="text" class="input-large" placeholder="Tu email aqui..." required>
<input ng-model="password" type="password" class="input-large" placeholder="Tu password aqui..." required>
</div>
<button ng-click="login()" ng-show='addMode' class="btn btn-success">Sign In</button>
</form><!-- end form -->
</div><!-- end div form-main -->
<div class="form-footer">
<div class="row">
<div class="col-xs-7">
<i class="fa fa-unlock-alt"></i>
Forgot password?
</div>
<div class="col-xs-5">
<i class="fa fa-check"></i>
Sign Up
</div>
</div>
</div>
</div>
</div>

Resources