I got a form on my modal, my plan was just to call a function for the submit but it doesn't do anything. The modal call is from my controller after clicking a submit button.
Controller
modal.popup({
title: "Title",
templateUrl:
"page.html",
size: "lg",
item: data,
});
Modal
popup: function(params) {
var modal;
modal = openOmniModal(
{
id: params.id,
item: params.item,
successCallback: function () {
if (
params.datatable &&
typeof params.datatable.refreshList === "function"
) {
params.datatable.refreshList();
}
if (
params.successCallback &&
typeof params.successCallback === "function"
) {
params.successCallback.apply(undefined, params.successCallbackParams);
}
$timeout(function () {
modal.close();
}, 1000);
},
errorCallback: function () {
if (
params.datatable &&
typeof params.datatable.refreshList === "function"
) {
params.datatable.refreshList();
}
if (params.errorCallback && typeof params.errorCallback === "function") {
params.errorCallback.apply(undefined, params.errorCallbackParams);
}
},
params: params.params,
close: function () {
modal.close();
},
modal: {
dismissable: true,
title: params.title || "",
subtitle: params.subtitle || "",
templateUrl: params.templateUrl,
},
},
params.windowClass || "modal-primary",
params.size
);
}
HTML
<form class="form" name="form" ng-submit="service.function(form, data)">
<div class="form-group">
<label for="exampleFormControlTextarea1">TextArea</label>
<textarea class="form-control" id="comment" rows="3" maxlength="1000"></textarea>
</div>
<div class="form-group row">
<div class="col-md-3">
<input type="submit" value="Cancel" id="btn-cancel" class="btn btn-block btn-outline" ng-click="close()">
</div>
<div class="col-md-3">
<input type="submit" value="Save" id="btn-save" class="btn btn-block btn-primary">
</div>
</div>
</form>
I've tried to add a handler on my controller this.submit but it still didn't work. Any ideas on what part I am wrong and what can I do to improve it?
Related
I am struggling to make it work to pass element id to Jquery from html foreach loop. I have a table and I am getting the details from database. so in each loop we are getting new data for new users. I am using bootstrap switch as seen below :
<form method="post" id="toggleForm">
<fieldset>
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="customSwitch1" name='machine_state' status="{{$detail['status']}}">
<input type="hidden" id="id" value="{{$detail['id']}}" >
<label class="custom-control-label" id="statusText" for="customSwitch1"> </label>
<llittle id ="littleupdate"></llittle>
</div>
</div>
</fieldset>
</form>
In the Jquery part we have three functions as shown below:
function putStatus() {
var id = $("#id").val();
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "post",
url: "/admin/check-status",
data: {id : id},
success: function (result) {
if (result == "true") {
$('#customSwitch1').prop('checked', true);
statusText(1);
} else {
$('#customSwitch1').prop('checked', false);
statusText(0);
}
}, error:function (){
}
});
}
function statusText(status_val) {
if (status_val == 1) {
var status_str = "Active";
} else {
var status_str = "Inactive";
}
document.getElementById("statusText").innerText = status_str;
}
function onToggle() {
$('#toggleForm :checkbox').change(function () {
if (this.checked) {
//alert('checked');
updateStatus(1);
// statusText(1);
} else {
//alert('NOT checked');
updateStatus(0);
// statusText(0);
}
});
}
function updateStatus(status_val) {
var id = $('#id').val();
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "POST",
url: "/admin/set-status",
data: {status: status_val, id:id},
success: function (result) {
if(result =="true") {
if(status_val == 1) {
$('#customSwitch').prop('checked', true);
// $("#updatedAt").fadeIn(0).html("<font color='green' font size='2px'> - Updated.. User Activated!</font>").fadeOut(1500);
// $( '#littleupdate').fadeIn(0).html("<font color='green' font size='1px'> Updated.. </font>").fadeOut(1500);
statusText(1);
} else if(status_val == 0){
$('#customSwitch').prop('checked', false);
// $("#updatedAt").fadeIn(0).html("<font color='green' font size='2px'> - Updated.. User Deactivated!</font>").fadeOut(1500);
// $( '#littleupdate').fadeIn(0).html("<font color='green' font size='1px'> Updated.. </font>").fadeOut(1500);
statusText(0);
}
} else {
if(status_val == 1){
$('#customSwitch1').prop('checked', false);
$("#updatedAt").fadeIn(0).html("<font color='red'> - Error while updating!</font>").fadeOut(1500);
} else if(status_val == 0){
$('#customSwitch1').prop('checked', true);
$("#updatedAt").fadeIn(0).html("<font color='red'> - Error while updating!</font>").fadeOut(1500);
}
}
}, error:function (){
}
});
}
$(document).ready(function () {
//Called on page load:
putStatus();
onToggle();
statusText();
});
Html loop as a whole is looking like below:
#foreach($details as $detail)
<tr>
<td>
{{$detail['id']}}
</td>
<td>
{{$detail['name']}}
</td>
<td>
{{$detail['type']}}
</td>
<td>
{{$detail['email']}}
</td>
<td>
<img src="{{asset('/admin/images/avatars/'.$detail['image'])}}">
</td>
<td>
{{$detail['mobile']}}
</td>
<td>
<form method="post" id="toggleForm">
<fieldset>
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="customSwitch1" name='machine_state' status="{{$detail['status']}}">
<input type="hidden" id="id" value="{{$detail['id']}}" >
<label class="custom-control-label" id="statusText" for="customSwitch1"> </label>
<llittle id ="littleupdate"></llittle>
</div>
</div>
</fieldset>
</form>
</td>
I really can't figure out the mechanism of passing the function to each loop element, as it only works correctly for the first instance in the table as can be seen in image below. Your help would be highly appreciated.
Because in loop , the id attribute is the same
In loop
<form method="post" id="toggleForm_{{$detail['id']}}">
<fieldset>
<div class="form-group">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="customSwitch_{{$detail['id']}}" name='machine_state' status="{{$detail['status']}}">
<input type="hidden" class="statusForDetail" value="{{$detail['id']}}" >
<label class="custom-control-label" id="statusText_{{$detail['id']}}" for="customSwitch_{{$detail['id']}}"> </label>
<llittle id="littleupdate_{{$detail['id']}}"></llittle>
</div>
</div>
</fieldset>
</form>
function putStatus() {
$(".statusForDetail").each((index, element) => {
let id = $(element).val()
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "post",
url: "/admin/check-status",
data: {id : id},
success: function (result) {
if (result == "true") {
$('#customSwitch_'+id).prop('checked', true);
statusText(1);
} else {
$('#customSwitch_'+id).prop('checked', false);
statusText(0);
}
}, error:function (){
}
});
});
}
I have to call a POST function, and need to compress the data in web form into an object in advance. I use ng-repeat to display all data input, and init this value for input, but I have no idea how to use ng-model to save the data.
I can resolve this case by setting an dynamic id for input, and using JQuery to get data, but it's not a good solution. And I want use AngularJS model only.
Please give me an advice. Below is my code:
Click here to see the screenshot of UI form
html file
<!-- edit-user-page-view -->
<div spectrum-error-container
data-scope-id="$id"
class="col-sm-12"></div>
<div class="email-preference-block">
<form name="editUserForm"
id="editUserForm"
role="form"
class="prj-form prj-create-user-form">
<fieldset id="fieldsetAccountInformation">
<legend>{{ 'user.userPage.form.fieldsets.accountInformation' | translate }}</legend>
<div class="row language-preference-block">
<div class="form-group">
<div class="col-md-12 col-sm-12">
<label data-translate="user.userPage.form.preferredLanguage"></label>
</div>
<div class="col-md-12 col-sm-12">
<label data-ng-repeat="option in preferencesData.languageOptionList"
class="radio-inline">
<input type="radio"
ng-model="emailNotificationModel.selectedLanguageValue"
value="{{ option.value }}"> {{ option.label | translate }}
</label>
</div>
</div>
</div>
<div class="row user-preference-block">
<table data-ng-repeat="preferenceItem in preferencesData.userNotificationPreferencesList"
class="table table-bordered table-striped user-preference-table">
<thead>
<tr>
<th>{{ preferenceItem.label | translate }}</th>
<th>{{ 'organisation.mediaPreference.selected' | translate }}?</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="mediaOption in preferenceItem.mediaOptionList">
<td class="first-column">
{{ mediaOption.label | translate}}
</td>
<td class="second-column">
<input type="checkbox"
id="inputStatus1-{{ mediaOption.id }}"
value="{{ mediaOption.id }}"
ng-checked="mediaOption.userChoice"
data-ng-click="clickHandler.checkValue(mediaOption.id)">
</td>
</tr>
</tbody>
</table>
</div>
<div class="prj-form-actions"
data-spectrum-style-affix
data-threshold="150"
data-css-class="sdx-sticky-container">
<button id="selectAllButton"
class="btn btn-default"
type="button"
data-ng-click="clickHandler.selectAll()"
data-translate="global.buttons.selectAll">
</button>
<button id="deselectAll"
class="btn btn-default"
type="button"
data-ng-click="clickHandler.deselectAll()"
data-translate="global.buttons.deselectAll">
</button>
<button id="saveBtn"
class="btn btn-default"
type="button"
data-ng-click="clickHandler.saveButton()"
data-translate="global.buttons.save">
</button>
<button id="cancelBtn"
class="btn btn-default"
type="button"
data-ng-click="clickHandler.deselectAll()"
data-translate="global.buttons.cancel">
</button>
</div>
</fieldset>
</form>
</div>
<div class="clearfix"></div>
<!-- / edit-my-account-page-view -->
controller file:
angular.module(
'EditUserPreferencesPageControllerModule',
[]
).controller(
'EditUserPreferencesPageController',
[
'$scope',
'$location',
'$routeParams',
'$filter',
'$window',
'$modal',
'PageTitleModel',
'SpectrumPageHeaderModel',
'AccountModel',
'UserModel',
'OrganisationService',
'RolesModel',
'MediaPreferencesModel',
'UserService',
'EmailNotificationService',
'EmailNotificationModel',
'SpectrumErrorModel',
'SpectrumHATEOASHelper',
function ($scope,
$location,
$routeParams,
$filter,
$window,
$modal,
PageTitleModel,
SpectrumPageHeaderModel,
AccountModel,
UserModel,
OrganisationService,
RolesModel,
MediaPreferencesModel,
UserService,
EmailNotificationService,
EmailNotificationModel,
SpectrumErrorModel) {
var impersonateUserCode = AccountModel.account.impersonatedUserCode,
userCode = impersonateUserCode ? impersonateUserCode : $routeParams.userCode;
$scope.mediaPreferencesModel = MediaPreferencesModel;
$scope.userModel = UserModel;
$scope.emailNotificationModel = EmailNotificationModel;
$scope.rolesModel = RolesModel;
$scope.statusList = [];
$scope.relationshipNotificationList = [];
$scope.auditNotificationList = [];
$scope.testListMediaValue = [];
$scope.preferencesData = {};
$scope.pleaseSelect = $filter('translate')('global.placeholders.pleaseSelect');
function initialise() {
PageTitleModel.setTitle('user.pageTitles.emailNotification');
SpectrumPageHeaderModel.setTitle('user.pageTitles.emailNotification');
SpectrumErrorModel.clearErrorsForScope($scope.$id);
generateOptions();
loadUserData();
}
function generateOptions() {
for (var status in MediaPreferencesModel.STATUS) {
if (MediaPreferencesModel.STATUS[status].domainType === 'Relationship') {
$scope.relationshipNotificationList.push(MediaPreferencesModel.STATUS[status]);
} else if (MediaPreferencesModel.STATUS[status].domainType === 'Audit') {
$scope.auditNotificationList.push(MediaPreferencesModel.STATUS[status]);
}
}
}
function loadUserData() {
UserService.getOne(userCode).then(
function successHandler(successResponse) {
UserModel.populateFromJSON(successResponse.data);
getNotificationPreferences();
},
function errorHandler(errorResponse) {
SpectrumErrorModel.handleErrorResponse($scope.$id, errorResponse);
}
);
}
function getNotificationPreferences() {
EmailNotificationService.getNotificationPreferences(UserModel.userCode).then(
function successHandler(successResponse) {
$scope.preferencesData = successResponse.data;
EmailNotificationModel.populateData($scope.preferencesData);
},
function errorHandler(errorResponse) {
SpectrumErrorModel.handleErrorResponse($scope.$id, errorResponse);
}
);
}
function saveData() {
var a = $scope.testListMediaValue;
EmailNotificationService.saveNotificationPreferences(UserModel.userCode, EmailNotificationModel.getJsonForSavePreferences()).then(
function successHandler(successResponse) {
console.log(successResponse);
},
function errorHandler(errorResponse) {
SpectrumErrorModel.handleErrorResponse($scope.$id, errorResponse);
}
);
}
$scope.clickHandler = {
saveButton: function () {
saveData();
},
backButton: function () {
$location.path(viewUserPath());
},
selectAll: function () {
angular.forEach(MediaPreferencesModel.relationshipStatus, function (itm) {
itm.userChoice = true;
});
},
deselectAll: function () {
angular.forEach(MediaPreferencesModel.relationshipStatus, function (itm) {
itm.userChoice = false;
});
},
checkValue: function (isChecked) {
console.log(isChecked);
}
};
function viewUserPath() {
return '/user/view/' + userCode;
}
$scope.canShow = {
emailPreferences: function () {
var preferenceFields = MediaPreferencesModel.preferenceFields;
return (preferenceFields.length > 0);
},
isRelationshipNotification: function (reference) {
return reference.domainType === 'Relationship';
},
isAuditNotification: function (reference) {
return reference.domainType === 'Audit';
}
};
initialise();
}
]
);
model
angular.module(
'EmailNotificationModelModule',
[]
).factory(
'EmailNotificationModel', [
function () {
return {
selectedLanguageValue: '',
userNotificationPreferencesList: [],
getJsonForSavePreferences: function () {
var json = {};
json.selectedLanguageValue = this.selectedLanguageValue;
json.userNotificationPreferencesList = this.userNotificationPreferencesList;
return json;
},
populateData: function (preferencesData) {
this.selectedLanguageValue = preferencesData.selectedLanguage.value;
}
};
}
]
);
JSON parse when I call get function to generate form
{
selectedLanguage: {
label: 'Spain',
value: 'sp'
},
languageOptionList: [
{
label: 'English',
value: 'en'
},
{
label: 'Chinese',
value: 'cn'
},
{
label: 'Spain',
value: 'sp'
},
{
label: 'French',
value: 'fr'
},
{
label: 'Portuguese',
value: 'po'
},
{
label: 'Japanese',
value: 'jp'
}
],
userNotificationPreferencesList: [
{
label: 'organisation.mediaPreference.tradingRelationships',
domainType: 'tradingRelationShip',
mediaOptionList: [
{
id: 'ACCEPTED',
label: 'organisation.relationshipStatuses.accepted',
order: 1,
userChoice: true
},
{
id: 'INITIATED',
label: 'organisation.relationshipStatuses.initiated',
order: 2,
userChoice: false
},
{
id: 'REJECTED',
label: 'organisation.relationshipStatuses.rejected',
order: 3,
userChoice: true
}
]
},
{
label: 'organisation.mediaPreference.auditNotifications',
domainType: 'auditNotification',
mediaOptionList: [
{
id: 'AUDIT_CREATED',
label: 'organisation.auditStatuses.created',
order: 4,
userChoice: true
},
{
id: 'AUDIT_ACCEPTED',
label: 'organisation.auditStatuses.accepted',
order: 5,
userChoice: false
}
]
}
]
};
The correct way to use NgModel with input[checkbox] can be found here.
For your implementation, change this
<input type="checkbox"
id="inputStatus1-{{ mediaOption.id }}"
value="{{ mediaOption.id }}"
ng-checked="mediaOption.userChoice"
data-ng-click="clickHandler.checkValue(mediaOption.id)">
To this
<input type="checkbox"
ng-model="mediaOption.userChoice"
ng-change="clickHandler.checkValue(mediaOption.id)">
I have a modal pop up.To open modal pop up i have a following code
mymodule.directive('modalDialogSite', function() {
return {
restrict: 'E',
scope: {
show: '='
},
replace: true,
transclude: true,
link: function(scope, element, attrs) {
scope.dialogStyle = {};
if (attrs.width)
scope.dialogStyle.width = attrs.width;
if (attrs.height)
scope.dialogStyle.height = attrs.height;
if (attrs.overflow)
scope.dialogStyle.overflow = attrs.overflow;
scope.hideModal = function() {
scope.show = false;
};
},
template: "<div class='ng-modal' ng-show='show'><div class='ng-modal-overlay'></div><div class='ng-modal-dialog' ng-style='dialogStyle'><div class='ng-modal-close' ng-click='hideModal()'><i class='fa fa-times-circle'></i></div><div class='ng-modal-dialog-content' ng-transclude></div></div></div>"
};
});
In view page the code like below
<a data-toggle="modal" role="button" class="btn btn-success" ng-click="add_site()" data-backdrop="static"><i class="icon-bookmark"></i><b>Add Site</b></a>
<modal-dialog-site show='modalShown_site'>
<?php echo $this->load->view('sites/modal_sites/content/add_website');?>
</modal-dialog-site>
When i click this button it goes to add_site() function in my controller i have given code like below
mymodule.controller('myCtrl',function($scope){
$scope.modalShown_site = !$scope.modalShown_site;
$scope.add_sute = function()
{
$scope.modalShown_site = ! $scope.modalShown_site;
}
});
Actually i have load my form here
<modal-dialog-site show='modalShown_site'> <?php echo $this->load->view('sites/modal_sites/content/add_website');?> </modal-dialog-site>
and my form will be like
<form id='frmAddSite' name='frmAddSite' novalidate angular-validator angular-validator-submit="add_website(frmAddSite)" class="form-horizontal form-validate" method="POST">
<label for="textfield" class="control-label">Name</label>
<input name='site_name' ng-model="text.site_name" required required-message="'Site name is required'" type="text">
<input type="submit" class="btn btn-primary" value="Submit">
<button type="button" ng-click="frmAddSite.reset();add_site_cancel()" class="btn" data-dismiss="modal" aria-hidden="true">cancel</button>
</form>
In this scenario how can get the form name into directives?
In this sample, we create a directive to get the some attributes name,id of a element form
app.directive('myDirective', function () {
return {
transclude: true,
template: '<div class="something" ng-transclude></div>',
link: function(scope, element) {
var formName = element.find("form").attr("name");
var formId = element.find("form").attr("id");
console.log(formName);
console.log(formId);
}
}
});
I just need to enable the button if all the forms is filled and disable it if not
**here is my code : **
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<form [formGroup]="OvertimeForm" (ngSubmit)="createOvertime()">
<div class="form-group">
<label class="control-label" for="employee" >Employee:</label>
<select2 [data]="employee"
[options]="options"
[width]="570"
[value]="employee_value"
(valueChanged)="changed($event)"
required>
</select2>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6">
<label>Start Time:</label>
<timepicker [(ngModel)]="start_time" [showMeridian]="ismeridian" formControlName="start_time" ></timepicker>
<button type="button" class="btn btn-info" (click)="toggleMode()">12H / 24H</button>
</div>
<div class="col-md-6">
<label>End Time:</label>
<timepicker [(ngModel)]="end_time" [showMeridian]="ismeridian" formControlName="end_time" ></timepicker>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-12">
<label>Reason</label>
<textarea class="form-control" name="remarks" id="remarks" rows="3" placeholder="Reason ..." formControlName="remarks" required></textarea>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary pull-right" [disabled]="!OvertimeForm.valid">Add</button>
</form>
but [disabled]="!OvertimeForm.valid" is not working
I use different package like time picker and select 2, they have their own function in getting their values
this is the code in my component
this.OvertimeForm = _fb.group({
'start_time': [this.ot.start_time, [Validators.required]],
'end_time': [this.ot.end_time, [Validators.required]],
'remarks': [this.ot.remarks, [Validators.required]],
'created_by': [this.ot.created_by, [Validators.required]]
});
}
ngOnInit() {
this.get_employee();
this.get_UserId();
}
get_UserId(){
this._auth_service.getUser().
subscribe(
data => {
let user = data; // fetched
this.user_id = user.id;
this.OvertimeForm.value.created_by = this.user_id;
},
err => console.error(err)
);
}
get_employee(){
let employees = this._common_service.getEmployees().
subscribe(
data => {
this.emp = Array.from(data); // fetched record
this.employee = this.emp;
this.employee_value = [];
this.options = {
multiple: true
}
this.current = this.employee_value;
},
err => console.error(err)
);
}
changed(data: any) {
this.current = data.value;
this.OvertimeForm.value.employee_id = this.current;
this.OvertimeForm.value.start_time = moment(this.start_time).format("HH:mm:ss");
this.OvertimeForm.value.end_time = moment(this.end_time).format("HH:mm:ss");
// this.OvertimeForm.valid = true;
// console.log(this.OvertimeForm.valid);
}
remarks(event:any){
let a = event;
console.log(a);
}
createOvertime(){
let ot = this.OvertimeForm.value;
console.log(ot);
this._OTservice
.createOT(ot)
.subscribe(
data => {
this.poststore = Array.from(data);
this.success_title = "Success";
this.success_message = "A new user record was successfully added.";
setTimeout(() => {
this.close();
}, 1000);
},
err => this.catchError(err)
);
}
private catchError(error: any){
let response_body = error._body;
let response_status = error.status;
if( response_status == 500 ){
this.error_title = 'Error 500';
this.error_message = 'The given data failed to pass validation.';
} else if( response_status == 200 ) {
this.error_title = '';
this.error_message = '';
}
}
//time picker
public toggleMode():void {
this.ismeridian = !this.ismeridian;
}
try this,
<button type="submit" [disabled]="!ngForm.valid">Submit</button>
Replace form tag line with :
<form #OvertimeForm=ngForm novalidate (ngSubmit)="createOvertime()">
Use: [attr.disabled]="!OvertimeForm.valid"
use novalidate in your form tag.
please find below code for reference.
OvertimeForm.html
<form [formGroup]="myNgForm" novalidate (ngSubmit)="saveAsConfirm(myNgForm)">
////other elements
<button type="submit" class="btn btn-success" [disabled]="!myNgForm.valid">Save</button>
</form>
hope this will help you.
I am trying to send the values from html to controller but is not goes to controller. What is the problem with this code value is show undefined at controller and factory. I hope this code is easy understood:
var mymodal = angular.module('mymodal', []);
mymodal.controller('MainCtrl', function($scope, loginfactory) {
$scope.showModal = false;
$scope.toggleModal = function() {
$scope.showModal = !$scope.showModal;
};
$scope.doLogin = function() {
var promise = loginfactory.logincheck($scope.userid, $scope.pwd);
}
});
mymodal.factory("loginfactory", function($http, $q) {
return {
"logincheck": function(userid, pwd) {
console.log(userid);
console.log(pwd);
return Object;
}
};
});
mymodal.directive('modal', function() {
return {
template: '<div class="modal fade">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" aria-hidden="">×</button>' +
'<h4 class="modal-title">{{ title }}</h4>' +
'</div>' +
'<div class="modal-body" ng-transclude=""></div>' +
'</div>' +
'</div>' +
'</div>',
restrict: 'E',
transclude: true,
replace: true,
scope: true,
link: function postLink(scope, element, attrs) {
scope.title = attrs.title;
scope.$watch(attrs.visible, function(value) {
if (value == true)
$(element).modal('show');
else
$(element).modal('hide');
});
$(element).on('shown.bs.modal', function() {
scope.$apply(function() {
scope.$parent[attrs.visible] = true;
});
});
$(element).on('hidden.bs.modal', function() {
scope.$apply(function() {
scope.$parent[attrs.visible] = false;
});
});
}
};
});
My view:
<div ng-controller="MainCtrl" class="container">
<h1>Modal example</h1>
<button ng-click="toggleModal()" class="btn btn-default">Open modal</button>
<modal title="Login form" visible="showModal">
<form role="form">
<div class="form-group">
<label for="email">Email address</label>
<input type="text" class="form-control" ng-model="userid" placeholder="Enter email" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" ng-model="pwd" placeholder="Password" />
</div>
<button type="submit" ng-click="doLogin()" class="btn btn-default">Submit</button>
</form>
</modal>
</div>
Here is what I mean see Plunker;
In your directive you used: scope: true, this mean what is change in the directive will not reflect on the parent scope Look at this so to get it works you have to do like this. in the submit btton: (angular best practice passing scope from view)
<button ng-click="doLogin(userid,pwd)" class="btn btn-default">submit</button>
in your controler:
$scope.doLogin = function(userid,pwd) {
var promise = loginfactory.logincheck(userid, pwd);
}
you see I don't pass $scope.userid and $scope.pwd in your loginfactory but pass the value from view because of scope: true, make your code won't work.
one last suggest, you can use UI bootstrap for angular so you don't have to mix with jquery bootstrap. UI Bootstrap