I've used generator-angular-fullstack with a freshly made route client/app/login. It contains login.controller.js, login.html, login.js, login.controller.spec.js and login.scss. I've set up a sign-in API endpoint I would like to save "authentication_token" and "user_id" from the JSON it returns to a cookie. Angular-cookies (ngCookies) is installed.
I've tried adapting the documentation examples (https://docs.angularjs.org/api/ngCookies/service/$cookies), but not much luck so far. Console error = '$cookies.put is not a function' (Angular 1.5.6). Also, changing
angular.module('myApp');
to
angular.module('myApp', ['ngCookies']);
or even
angular.module('myApp', ['']);
already makes the login page go blank, except for the header. I don't think it's matter of the module not existing, since trying to load a non-existing module gives a completely blank page (no header either).
Any suggestions?
login.html
<body>
<script src="/bower_components/angular-cookies/angular-cookies.js"></script>
<form ng-submit="callSignIn(username, password, site)">
Email:
<input type="text" ng-model="username"><br>
Password:
<input type="text" ng-model="password"><br>
Site:
<input type="text" ng-model="site"><br>
<input type="submit" value= "Submit">
</form>
<section ui-view>Response: {{response}}</section>
</body>
login.controller.js
'use strict';
(function(){
class LoginComponent {
constructor($scope, $http, $cookies) {
$scope.callSignIn = function(username, password, site) {
$http.post('/api/auth/signin', {
username: username,
password: password,
site: site
}).success(function(response, $cookies) {
$scope.response = response;
$cookies.put('myFavorite', 'oatmeal'); //testvalue
});
};
}
}
angular.module('orbitApp') //angular.module('orbitApp', ['ngCookies']) gives blank login page...
.component('login', {
templateUrl: 'app/login/login.html',
controller: LoginComponent
});
})();
login.js
'use strict';
angular.module('orbitApp')
.config(function ($stateProvider) {
$stateProvider
.state('login', {
url: '/login',
template: '<login></login>'
});
});
Typical JSON response:
{"http_code":200,"response":{"authentication_token":"a","site_id":"b","content_url":"c","user_id":"d"}}