last day (15 days later) » 

7:57 PM
0
A: Showing div in angularjs not working

pankajparkarYou should only maintain only one flag data.show that is more than sufficient to show hide div. <div ng-controller="controller"> <div ng-show="data.show"> Successfully triggered </div> <div ng-hide="data.show"> Error in triggering</div> </div> Controller app.controller('myCtrl', func...

 
If i want to show the successfully triggered text, then should i do like this ? $scope.data = { show: true, hide: false }; ?
Or may i know what should i do to show and hide it in success and failure condition ?
 
@Preethi you should only care about doing true false for $scope.data = { show: true}
 
@pankar : By default the Successfully triggered is visible, when i try to do $scope.data = { show: true} the message was the same and no actions was there .. :(
 
@Preethi try updated solution..
 
Yes, i am trying it.. Actually i have this in the app.js first line function controller($scope) { $scope.data = { show: true, hide: false }; } Is that araise any problem ?
Because without the above code, i am getting errors in my console when the page is render itself
I have this error when i try the updated code ... after the button press Cannot set property 'show' of undefined
 
7:57 PM
@Preethi read my 1st line carefully you should write $scope.data = { show: false }; line in you controller somewhere,,and then you need to use if(results.data=='success') { $scope.data.show = true; //success } else { $scope.data.show = false; //error } in your function
 
sorry, when i put this $scope.data = { show: false }; at the first line of the controller, it shows me this error Error: [ng:areq] http://errors.angularjs.org/1.2.16/ng/areq?p0=controller&p1=not%20aNaNunction%2C‌​‌​%20got%20undefined at Error (native) and displaying both the div elements in the html page
Hi sir
Sorry, if i don't understand. I defined
$scope.data = { show: false };
in the top of my controlller.js
and having
<div ng-controller="controller">
<div ng-show="data.show"> Successfully triggered </div>
<div ng-hide="data.show"> Error in triggering</div>
</div>
this in the html
which gives me the following error
Error: [ng:areq] http://errors.angularjs.org/1.2.16/ng/areq?p0=controller&p1=not%20aNaNunction%2C%20got%20undefined
at Error (native)
 
could you put your controller code here
controller name should n
should n;t be controller
It have to different so that it will not conflict with any other thing
 
the name of the controller is appCtrl.js
i just told you roughly..
Here is the screen of my error i.imgur.com/8qSCNkS.png
 
Could you put your controller code here
 
Sure,
Here is the fiddle
I am using it in the doLog() function
$scope.doLog={email:'',password:''};
$scope.doLog = function ()
{
email = $scope.login.email;
password = $scope.login.password;
$http.post('AuthenticateUser', { email : email, password: password}).then(function (results)
{
if(results.data=='success')
{
$scope.data.show = false;
$location.path('dashboard');
}
else
{
alert('Invalid Username or Password');
$scope.data.show = true;
}
});
};
 
8:11 PM
Ok
 
Ok sir, pls see it :)
 
Let me figure it out
No sir
I'm just an ordinary developer
are you from India?
 
thanks
yes i am
 
Cool
me tooo
 
that's great :)
 
8:13 PM
why you are doing coding in late night then?
do replace this ` $scope.doLog = {
email: '',
password: ''
};` with ` $scope.data = {
email: '',
password: ''
};`
 
just to give demo by tomorrow
 
do replace this `$scope.doLog = {
email: '',
password: ''
};` with `$scope.data = {
email: '',
password: ''
};`
Still you are in office?
 
nope :)
yes i repplaced now
It throws
Uncaught SyntaxError: Unexpected identifier
 
then what is the result?
sorry
my bad
let me correct it
 
It makes the form submit
Yes pls :)
If you want, i can show my system by teamviewer :)
 
8:19 PM
Nope
No ned
I'm going to sleep now
In few mins
 
Oh that's ok
 
$scope.doLog = {
email: '',
password: ''
};

$scope.doLog = function () {
email = $scope.login.email;
password = $scope.login.password;
$http.post('AuthenticateUser', {
email: email,
password: password
}).then(function (results) {
if (results.data == 'success') {
$scope.data.show = true;
$location.path('dashboard');
} else {
alert('Invalid Username or Password');
$scope.data.show = true;
}
});
};
look at this code
you are declaring variable an function with ssame name
$scope.doLog = {
email: '',
password: ''
};
 
that is to define the email and password,,
is that wrong ?
 
this is declaring variable doLog but in next line you are making it as function
which is vanishing the existance of varible
 
then what shall i do ..
 
8:23 PM
you should use different name for the function
that will solve you issue
 
ok, i will try with that
 
That will definitly going to work
trust me
 
I just removed $scope.doLog={email:'',password:''}; and have only
$scope.doLog = function ()
{
email = $scope.login.email;
password = $scope.login.password;
$http.post('AuthenticateUser', { email : email, password: password}).then(function (results)
{
if(results.data=='success')
{
$scope.data.show = false;
$location.path('dashboard');
}
else
{

$scope.data.show = true;
}
});
};
even it throws error in the beginning itself :(
 
What is the error now?
 
Error: [ng:areq] http://errors.angularjs.org/1.2.16/ng/areq?p0=controller&p1=not%20aNaNunction%2C%20got%20undefined
at Error (native)
 
8:31 PM
By the way you should also have $scope.login={email:'',password:''}; sowhere in your controller
 
i had it in the coontroller,
now the same error again..
 
really wiered
 
I am looking at this code in 8 hours
 
8:46 PM
Reallu
Thats horrible
 
but, i just wanted to show a simple error message, rather than showing alert
I never though it would be such a mess :(
 
No that is not messable thing
 
*thought
 
you must have missed something
 
But showing a simple error message is such a big thing,,, ? :(
I showed you all my js ..
 
8:48 PM
Nope
not at all
 
Or can you tell me a simple way to show alert to user
 
could you tell me what is the error?
now you are getting
plese send screen shot
 
yes sure
but before that,,,
may i know any simple way to alert the user
because just now i reverted the code to show error message in alert box,
if you can , can you pls tell a better way to show the error message to user, like in showing the error in div
 
use alertify.js
could you tell you teamviewer Id
 
will that conflict with angular ?
 
8:52 PM
I will look at your code first
 
589 259 825
5446
 
what is it actually
tell me again
fast please
 
which one u ask
i just posted the teamviewer id
above
 
what is the password?
 
5446
 
8:58 PM
Is it a correct page
I m looking at
 
9:41 PM
thanks:)
 
9:58 PM
Yes
Glad to help you..I don;t see You are doing thing which I told you so many Times :(
 

last day (15 days later) »