together
- Pull down this repository
- Check out what it is
- Add
ng-model
to the username<input>
field
- give it a value of "username"
- Do the same for password
on your own
- Create a new
<div>
immediately after the<form>
element - Give it classes of
well
andcol-md-6
- aren't well's cool?
- Put in a couple of
{{ expressions }}
forusername
andpassword
together
- Create a Controller with the name "FormController" in the app.js file
- Attach the Controller using
ng-controller
to the<div>
parent of the<form>
- Create an initial value for
username
from within the Controller js code
- inject the
$scope
service into your controller - set
$scope.username = "something";
together
- Attach a new function to the
$scope
service called "login"
$scope.login = function(){ ... };
- Add a
console.log
in there to let us know it's being hit - Create an
ng-submit
on the<form>
and give itlogin()
- Try it out
together
- Change what's in the
ng-controller
to:ng-controller="FormController as vm"
- Assign
var vm = this;
in your Controller js - Attach each of the variables there to the
vm
object - Change all variables in the
FormController
to be values on thevm
object
- username
- password
- submit()
- Now don't ever use
$scope
for variables or custom functions again!
on your own
- Remove the initialization of
username
in the Controller's js, that's silly - Make sure both of the fields are filled in using the
required
attribute - Create an array for
logins
on thevm
object - When someone logs in, add the username and current time to the
logins
array console.log
thelogins
array- Clear the values of
username
andpassword
when submitted
on your own
- Remove the expressions on the right of the form, we don't need them
- Instead, use
ng-repeat
to output thelogins
array to thatwell
;)
together
- Install
angular-mocks
withbower
- Clear the current specs.js file
describe
the controllerbeforeEach
test, register the module
beforeEach(angular.mock.module('logintrest'));
- note: angular-mocks registers
module
on the global scope as well
- Try to run a dummy test
- Fix Karma
- angular-mocks depends on angular, so angular needs to be loaded first with Karma
together
- Add a new var
formController
to thedescribe
s scope - Add the following
beforeEach
after the other one:
beforeEach(angular.mock.inject(function($controller){
formController = $controller('FormController');
}));
together
- Create a describe for
login()
- Create an
it
for "should clear the values of username and password"
- set the values of
formController.username
andformController.password
- launch the
login()
expect
them to be blank
on your own
- Figure it out!
on your own
- Use
ng-click
- Remember the ng-repeat syntax that lets you get the index?
ng-repeat="(key, value) in array"
on your own
- Set up the
logins
array - Test to see if it removed one