Angular-ui router doesn't update links - angularjs

I am building a basic rss reader, Ihave a basic form which uploads a series of url into a dropdown menu, when a user chooses a specific one, I call an api to access it.
My form is the following:
<div class="panel-body" ng-controller="NewsCtrl">
<form class="form-inline" role="form">
<div class="input-group">
<div class="input-group-btn">
<button class="btn btn-info" type="button">{{loadButtonText}}</button>
<button class="btn btn-info dropdown-toggle" type="button" data-toggle="dropdown"><span class="caret"></span><span class="sr-only">Toggle-dropdown</span></button>
<ul class="dropdown-menu" role="menu">
<li ng-repeat="rss in RSSList">
{{rss.Title}}
</li>
</ul>
<input type="text" class="form-control" autocomplete="off" placeholder="This is where your feed's url will appear" data-ng-model="url">
</div>
</div>
</form>
My routes/states are defined as follows:
var myApp = angular.module('myApp',['ngSanitize','ui.router', 'myAppControllers', 'myAppFactories']);
myApp.config(['$stateProvider','$urlRouterProvider','$locationProvider',
function ($stateProvider,$urlRouterProvider,$locationProvider) {
$stateProvider
.state('home', {
url:'/home',
templateUrl: 'views/partials/partial-home.html'
})
.state('app', {
url:'/api',
templateUrl: 'views/partials/partial-news.html',
controller: 'NewsCtrl'
});
$urlRouterProvider.otherwise('/home');
$locationProvider
.html5Mode(true)
.hashPrefix('!');
}]);
And my controller is the following:
var myApp = angular.module('myAppControllers',[]);
myApp.controller('NewsCtrl', ['$scope','MyService', function($scope, Feed){
$scope.loadButtonText = 'Choose News Feed ';
$scope.RSSList = [
{Title: "CNN ",
url: 'http://rss.cnn.com/rss/cnn_topstories.rss'},
{Title: "CNBC Top News ",
url: 'http://www.cnbc.com/id/100003114/device/rss/rss.html'},
];
//Loading the news items
$scope.loadFeed = function (url, e) {
$scope.url= url;
Feed.parseFeed(url).then(function (res) {
$scope.loadButtonText=angular.element(e.target).text();
$scope.feeds=res.data.query.results.item;
});
}
}]);
My problem arised when I changed to use ui-router, I know I have to change this line
{{rss.Title}}
by using ui-sref, but just changing to <a ui-sref="loadFeed(rss.url, $event);">{{rss.Title}}</a>
still doesn't upload my urls into my NewsCtrl controller, any clues?
Bonus question: When I insert a console.log just before $scope.loadButtonText and I open the developer console, it seems to upload NewsCtrl 2 times, why is that?

ui-sref="app"
Should work.
sref stands for "state" reference, instead of the familiar "hyperlink" reference. So it will look for a state defined with .state();
Alternatively, you can go with a good old fashioned url,
href="#/api"
This would have the same effect. sref is recommended by project developers.

Related

UI-Router Child/nested state does not load

I've had a look at similar questions, but their problem seems to resolve around the lack of <ui-view /> tag in the parent HTML. Here, it's not the case.
I have a child state that does not load:
routes.js
angular.module('myapp').config(function($stateProvider, $locationProvider, $urlRouterProvider){
$urlRouterProvider.otherwise('/');
//A bunch of unrelated routes
$stateProvider.state({
'name': 'users',
'url': '/users',
'controller': 'usersCtrl',
'templateUrl': '/scripts/pages/users/users.html'
});
$stateProvider.state({
'name': 'users.editeduser',
'url': '/editeduser',
'template': '<h1>HELLO</h1>'
// 'templateUrl': '/scripts/pages/users/parts/editedUser.html',
// 'controller': 'editedUserCtrl'
// 'resolve': {
// editedUserId: function(editedUserId) {
// return editedUserId;
// }
// }
});
users.html
<div class="panel panel-default">
<div class="panel-heading">
<h3>Users List</h3>
</div>
<div class="panel-body">
<ul class="list-group">
<li class="list-group-item" ng-repeat="user in users track by $index">{{user.firstname + " " + user.lastname}}</li>
</ul>
<ui-view name="users.editeduser"></ui-view>
</div>
<div class="panel-footer">
<button class="btn btn-primary" ui-sref="user-edit">New User</button>
</div>
</div>
In the html code uiview line, I tried using <ui-view name=".editeduser"></ui-view> and I also tried just <ui-view name="editeduser"></ui-view> to no avail. I even tried <div ui-view=....
As you can see in the commented out routes.js code, there is a supposed controller and html template that the child is supposed to have, but I removed them for the sake of trying to work out the problem.
In Chrome Dev Tools, this is the output:
Any help would be appreciated. Thanks
The ui-sref for the button doesn't match the url for that state:
<div class="panel-footer">
<!-- ERRONEOUS
<button class="btn btn-primary" ui-sref="user-edit">New User</button>
-->
<!-- INSTEAD -->
<button class="btn btn-primary" ui-sref="users/editeduser">New User</button>
</div>
I think you're onto something though because at no where to I call the child state in my code, and I think I need to call it for it to be loaded, but I am not sure of how to. I'll try to look at the documentation and see –
The UI-Router for AngularJS (1.x) - Hello Galaxy! Tutorial has a DEMO that shows a state with a list of people. The child view with information on an individual only becomes visible when the person is selected.
The DEMO on PLNKR

Using a controller as uibModal Controller

So I am working on a module called "ShowTree".
Before this, I have a controller named "InviteUserCtrl". Inside the ShowTree module, there is a button that will show a uibModal that is used to add new user.
Basically this uibModal in ShowTreeCtrl is all exactly the same as InviteUserCtrl. So, instead of copy pasting all the code from the InviteUserCtrl to the new uibModalController, I decided to inject the InviteUserCtrl as the uibModalController.
The problem is I can't use the InviteUserCtrl as my uibModalController
here is my html code in ShowTree list.html
<div ng-controller="inviteUserCtrl as vm">
<script type="text/ng-template" id="inviteUser.html">
<div class="modal-header">
<h3 class="modal-title">Invite User</h3>
</div>
<div class="modal-body">
<span ng-include="'app_view/modules/invite_user/form.html'"></span>
<br><br>
</div>
<div class="modal-footer">
<button class="btn btn-warning" type="button" ng-click="vm.cancel()">Back</button>
</div>
</script>
</div>
here is the code in my ShowTreeCtrl
function open(size){
var modalInstance = $uibModal.open({
animation : true,
templateUrl: 'inviteUser.html',
controller: 'inviteUserCtrl as vm',
size: size,
});
}
Also i am using ui-router. here is my code in the router
.state('app.show_tree', {
url: '/show_tree/:action/:id',
templateUrl: base_view_url+'modules/show_tree/index.html',
data : { title: 'Show Tree' },
controller : "showTreeCtrl",
controllerAs : "vm",
resolve: load([
base_view_url+'modules/show_tree/showTreeCtrl.js',
base_view_url+'modules/invite_user/inviteUserCtrl.js',
'ui.select'
]),
params : {action:"list",id:null},
activetab: 'Activity'
})
The above code is able to display the form from the InviteUser module, but the controller seems doesn't work. The form button and the controller API do not run at all.
What am I missing here? thank you ..

Angular ui-router crashing browsers

So I have no idea what is wrong, but im assuming i have a loop running in the background of my code or that im routing incorrectly. But all i know is when i try to go to my index page, my entire browser is taken down, no errors or anything, just crashing. Any help would really be appreciated im just trying to move on from this problem.And in case this changes anything i am using a rails backend.
planoxApp.config(['$stateProvider','$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/',
templateUrl: 'templates/home/nav.html',
authenticate: true
})
.state('home.index', { // our home page
url: '/index',
views: {
"": {templateUrl: 'templates/home/home.html'},
"assembly#index": { templateUrl: "templates/home/assembly.html" },
"client#index": { templateUrl: "templates/home/client.html" },
"photoplan#index": { templateUrl: "templates/home/home_photoplan.html" }
},
authenticate: true
})
Here is the main routes causing problems, the home one is just a nav bar, and when you go to the home tab its supposed to take you to the index page, but no dice. Im not sure how much of my controller i should show, but here a small part.Its the parts that directly effect the routes.
app.run(function ($rootScope,$location, $localStorage){
$localStorage.recent = ""
$rootScope.$on('$routeChangeSuccess', function() {
console.log("working")
recent.push($location.$$path);
});
});
app.run(function ($rootScope, $state, AuthService) {
$rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams){
if (toState.authenticate && !AuthService.isAuthenticated()){
// User isn’t authenticated
console.log(AuthService.isAuthenticated())
$state.transitionTo("login");
event.preventDefault();
}
});
});
// GET request Area
$http.get('client.JSON').success(function(data){
$scope.clients = data;
});
$http.get('photoplan.JSON').success(function(data){
$scope.photoplans = data;
$scope.complete = true;
// if(main.photoplans.plano_order_status === "Complete"){
// console.log()
// $scope.complete = true;
// }else{
// $scope.complete = false;
// }
});
$http.get('assembly.JSON').success(function(data){
// main.assemblys = $filter('filter')(data, function(d){return d.employee_id == mainid});
$scope.assemblys = data;
console.log($scope.assemblys)
});
$http.get('employee.JSON').success(function(data){
$scope.employees = data;
});
}]);
This is the index page, and one of the nested views it has, all the views look roughly the same.
<div class="container" ng-controller="MainCtrl">
<!-- Main Section -->
<div class="home no-subheader container">
<div class="row" >
<!-- left -->
<section name="assembly-queue" class="molding col-md-4" id="assembly">
<div class="gutter" >
<div ui-view="assembly"> </div>
</div>
</section>
<!-- <section name="employee-queue" ng-if="type === 'admin'" class="molding col-md-4" id="employee">
<div class="gutter" id="scrollArea">
<div ui-view=".employee"></div>
</div>
</section> -->
<!-- middle -->
<section name="clients" class="molding col-md-4" id="clients">
<div class="gutter" >
<div ui-view="client"> </div>
</div>
</section>
<!-- right -->
<section name="photoplans" class="molding col-md-4" id="photoplans">
<div class="gutter" >
<div ui-view="photoplan"> </div>
</div>
</section>
</div>
</div>
</div>
This is the assembly page.
<div id="expanding" >
<div class="top row">
<h2> Assembly Queue</h2>
<form class="navbar-form navbar-left default" role="search">
<div class="form-group">
<input type="text" ng-model="searchassembly" class="form-control query" placeholder="Search Assembly Queue">
</div>
</form>
</div>
</div>
<article class="assembly snippet row" ng-repeat="assembly in assemblys|filter:searchassembly" >
<div class="left col-xs-7" >
<address>{{assembly.address_part1}},{{assembly.address_part2}}</address>
<p class="timeline-data"> Due on {{assembly.date_due}}</p>
<p class="timeline-data"> Job Type: {{assembly.job_type}}</p>
<p class="timeline-data"> Delivery Type: {{assembly.delivery_type}}</p>
</div>
<div class="right col-xs-5 text-center">
<div class="corner-ribbon" ng-click="open(assembly.id)" > </div>
<button ng-if="assembly.new_order" class="btn btn-default" ui-sref="photoplans({ id : assembly.photoplan_id })" ><span class="fa fa-pencil-square-o" aria-hidden="true"></span></button>
<button ng-if="assembly.new_order === false" class="btn btn-default" ui-sref="assign({address : assembly.address, realtor: assembly.realtor})" ><span class="fa fa-external-link" aria-hidden="true"></span></button>
</div>
</article>
If anyone has had similar issues or can see red flags in this please let me know, i am really stuck on this issue.
Okay so i actually found the answer myself, and im leaving the solution here for future people who might have this issue. But basically i need to have word of some kind in my home route, so instead of just /, i need /home. Because the browser was trying to load this #//index, and that was causing crashes. When using rails and angular together, make sure to have named routes to prevent this problem. Also make sure your nested views look like this, whatever#parent.child. Heres my new code.
planoxApp.config(['$stateProvider','$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'templates/home/nav.html',
authenticate: true
})
.state('home.index', { // our home page
url: '/index',
views: {
"": {templateUrl: 'templates/home/home.html'},
"assembly#home.index": { templateUrl: "templates/home/assembly.html" },
"client#home.index": { templateUrl: "templates/home/client.html" },
"photoplan#home.index": { templateUrl: "templates/home/home_photoplan.html" }
},
authenticate: true
})

Multi-state Forms with Angular-Formly

I can't figure out how to do a multi-state form. The main issue is the form.$errors seem to look at the active state rather then the whole form. In other words, the submit button is meant to be disabled until ALL required questions are answered for the entire form, but it seems to become enabled when all the required questions are answered for the active state.
Here's a simplified Plunker: http://plnkr.co/edit/O49eO4uRlUjoWHlxV6Li?p=preview
And below is my actual code.
View:
<div class="row">
<div class="col-md-4">
<ul class="nav nav-pills nav-stacked">
<li role="presentation" ng-repeat="section in vm.sections[0].sections" ng-if="section.fields">
<a ui-sref="subject.items.new.section({sectionUrl: section.url})">
<span class="badge badge-warning" title="Number of unanswered required questions for {{section.name}}">1</span>
{{section.name}}
</a>
</li>
</ul>
</div>
<div class="col-md-8">
<form class="assessment-item" name="assessmentForm">
<div ui-view></div>
<hr>
<button class="btn btn-primary btn-raised" ng-disabled="assessmentForm.$invalid" ng-click="vm.createCompletedItem()">Save Changes</button>
<button class="btn btn-inverse btn-inverse-danger" back-button>Cancel</button>
</form>
</div>
</div>
Routes:
.state('subject.items.new', {
url: '/items/new/:availableItemUrl',
templateUrl: 'components/items/new.html',
controller: 'ItemNewCtrl',
controllerAs: 'vm',
resolve: {
getAvailableItemsResolve: function(DataService) {
return DataService.availableItems().getList();
},
getUser: function($cmUserData) {
return $cmUserData.getUser(1);
}
}
})
.state('subject.items.new.section', {
url: '/:sectionUrl',
template: '<div class="animated fadeIn"><formly-form model="vm.completedItem.answers" fields="vm.fields"></formly-form></div>',
controller: function($scope, $stateParams, lodash) {
var vm = this;
var _ = lodash;
vm.questions = _.filter($scope.vm.sections[0].sections, { 'url' : $stateParams.sectionUrl });
vm.fields = vm.questions[0].fields;
vm.completedItem = $scope.vm.completedItem;
},
controllerAs: 'vm'
})
itemNewCtrl:
(function() {
'use strict';
angular
.module('casemanagerApp')
.controller('ItemNewCtrl', ItemNewCtrl);
function ItemNewCtrl($stateParams, $filter, DataService, lodash, getUser, getAvailableItemsResolve) {
var vm = this;
var _ = lodash;
vm.item = DataService.completedItems().one();
vm.availableItems = getAvailableItemsResolve;
vm.sections = _.filter(vm.availableItems, { 'url' : $stateParams.availableItemUrl });
vm.completedItem = DataService.completedItems().one();
vm.completedItem.subjectId = $stateParams.subjectId;
vm.completedItem.name = vm.sections[0].name;
vm.completedItem.probationOfficer = getUser.firstName + ' ' + getUser.lastName;
vm.completedItem.label = 'Final';
}
})();
The issue is due to the way you have things set up. When I switch tabs, angular-ui-router removes the view entirely and therefore angular only sees one formly-form, therefore only one formly-form is validated at a time. I would recommend against using angular-ui-router and instead just use a directive (like angular-ui-bootstrap's tabset directive) which uses ng-show to keep both forms on the page at a time and therefore both will be taken into account when doing validation. Here's an example that might help you there.
All you need to do is set a flag, like "formComplete" in the model and then flip it on once they get to the last question...we have similar issues at work with something like this and that's how we work around it.
Alternatively you could simply move the submit button to the last page

Dynamic parameters with angular ui router

I am wondering how to include parameters when changing state and sending the request to get the template from the backend.
Here is my app:
angular.module('questionnaireApp', ['ngAnimate', 'ui.router', 'ui.bootstrap'])
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('questionnaire', {
url: '/questionnaire',
templateUrl: 'questionnaire/questionnaire.html',
controller: 'questionnaireCtrl'
})
.state('questionnaire.receiver_name', {
url: '/receiver_name',
templateUrl: 'questionnaire/receiver_name.html'
})
.state('questionnaire.location', {
url: '/location',
templateUrl: 'questionnaire/location.html'
})
.state('poem', {
url: '/poem',
templateUrl: 'questionnaire/poem.html',
controller: 'questionnaireCtrl'
});
$urlRouterProvider.otherwise('/questionnaire/receiver_name');
}])
.controller('questionnaireCtrl', ['$scope', '$http', '$state', function($scope, $http, $state) {
$scope.formData = {};
}]);
I am saving user input in $scope.formData. I need to include it in my request to be able to render questionnaire/poem.html.
Something like:
.state('poem', {
url: '/poem',
templateUrl: 'questionnaire/poem' + $scope.formData + '.html',
controller: 'questionnaireCtrl'
});
How can I do that?
Or is there any variant that can help me send the formData to my backend so that it can render the poem.html page properly?
You can do it by making the templateUrl a function. Take a look at this example, taken from ui-router documentation ( https://github.com/angular-ui/ui-router/wiki ):
$stateProvider.state('contacts', {
templateUrl: function ($stateParams){
return '/partials/contacts.' + $stateParams.filterBy + '.html';
}
})
In the above example, we get $stateParams as an argument (note, it's not an injection, more details on the doc site) and use the parameter "filterBy" as part of the template url. In your case, it's formData.
Note 1: You must pass a string. If formData is an object, you can't use it as part of the templateUrl, and you probably won't be able to even pass it as part of the stateParams. maybe you want a specific field from it? Something like 'formType'?
Note 2: As mb21 mentioned, all of this has nothing to do with the backend. if you want to send the form data, do a REST call. Routing should involve only the client side.
questionnaire/poem.html should be an Angular html template file, nothing dynamically generated by the server.
To save your data, use Angular's http service to do a post request to the server that wants the data.
If you have the data on PageA with ControllerA and need to have it on PageQ with ControllerQ, you should share the data using a factory between the two controllers. No need to involve the server.
I finally managed to achieve my goal: retrieve the poem with one HTTP request only.
To do that:
I store the HTML templates inside the Angular app so that it only needs to retrieve JSON data
form data is sent with regular http post
poem data is sent back in JSON format
the poem is displayed thanks to Angular data binding
Angular code:
angular.module('thePoetApp').config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$stateProvider
// route to show our basic form (/questionnaire)
.state('questionnaire', {
url: '/questionnaire',
templateUrl: 'questionnaire/questionnaire.html',
})
// nested states
// each of these sections will have their own view
// url will be nested (/questionnaire/receiver_name)
.state('questionnaire.receiver_name', {
url: '/receiver_name',
template: '<div class="col-md-3 text-left ng-scope"></div><div class="form-container col-md-6 text-center ng-scope"><div class="form-group"><label for="receiver_name">Receiver Name:</label><input name="receiver_name" ng-model="formData.receiver_name" receiver_name="receiver_name" required="" type="text" class="ng-pristine ng-invalid ng-invalid-required"></div><div class="form-group"><label for="receiver_sex">Receiver Sex:</label><input name="receiver_sex" ng-model="formData.receiver_sex" receiver_sex="receiver_sex" required="" type="radio" value="male" class="ng-pristine ng-invalid ng-invalid-required">Male<input name="receiver_sex" ng-model="formData.receiver_sex" receiver_sex="receiver_sex" required="" type="radio" value="female" class="ng-pristine ng-invalid ng-invalid-required">Female</div></div><div class="col-md-3 text-right ng-scope"><a class="btn btn-primary" ui-sref="questionnaire.location">Next Step</a></div>',
})
// url will be /questionnaire/location
.state('questionnaire.location', {
url: '/location',
template: '<div class="col-md-3 text-left ng-scope"><a class="btn btn-primary" ui-sref="questionnaire.receiver_name">Previous Step</a></div><div class="form-container col-md-6 text-center ng-scope"><div class="form-group"><label for="location">Location:</label><input location="location" name="location" ng-model="formData.location" required="" type="text" class="ng-pristine ng-invalid ng-invalid-required"></div></div><div class="col-md-3 text-right ng-scope"><a class="btn btn-primary" ui-sref="questionnaire.relationship">Next Step</a></div>'
})
// url will be /questionnaire/relationship
.state('questionnaire.relationship', {
url: '/relationship',
template: '<div class="col-md-3 text-left ng-scope"><a class="btn btn-primary" ui-sref="questionnaire.location">Previous Step</a></div><div class="form-container col-md-6 text-center ng-scope"><div class="form-group ng-scope" ng-controller="RelationshipsTypeaheadCtrl"><label for="relationship">Relationship:</label><input autocomplete="off" name="relationship" ng-model="formData.relationship" relationship="relationship" required="" type="text" typeahead-editable="false" typeahead="suggestion for suggestion in relationships($viewValue)" class="ng-pristine ng-invalid ng-invalid-required"><ul class="dropdown-menu ng-isolate-scope"><!-- ngRepeat: match in matches --></ul></div></div><div class="col-md-3 text-right ng-scope"><a class="btn btn-primary" ui-sref="questionnaire.trait">Next Step</a></div>'
})
// url will be /questionnaire/trait
.state('questionnaire.trait', {
url: '/trait',
template: '<div class="col-md-3 text-left ng-scope"><a class="btn btn-primary" ui-sref="questionnaire.relationship">Previous Step</a></div><div class="form-container col-md-6 text-center ng-scope"><div class="form-group ng-scope" ng-controller="TraitsTypeaheadCtrl"><label for="trait">Trait:</label><input autocomplete="off" name="trait" ng-model="formData.trait" trait="trait" required="" type="text" typeahead-editable="false" typeahead="suggestion for suggestion in traits($viewValue)" class="ng-pristine ng-invalid ng-invalid-required"><ul class="dropdown-menu ng-isolate-scope"><!-- ngRepeat: match in matches --></ul></div></div><div class="col-md-3 text-right ng-scope"><a class="btn btn-primary" ui-sref="questionnaire.message">Next Step</a></div>'
})
// url will be /questionnaire/message
.state('questionnaire.message', {
url: '/message',
template: '<div class="col-md-3 text-left ng-scope"><a class="btn btn-primary" ui-sref="questionnaire.trait">Previous Step</a></div><div class="form-container col-md-6 text-center ng-scope"><div class="form-group ng-scope" ng-controller="MessagesTypeaheadCtrl"><label for="message">Message:</label><input autocomplete="off" name="message" ng-model="formData.message" message="message" required="" type="text" typeahead-editable="false" typeahead="suggestion for suggestion in messages($viewValue)" class="ng-pristine ng-invalid ng-invalid-required"><ul class="dropdown-menu ng-isolate-scope"><!-- ngRepeat: match in matches --></ul></div></div>'
})
.state('poem', {
url: '/poem',
template: '<div class="poem"><p>{{ poem.title }}</p><p><div>{{ poem.intro_verse.line_one}}</div><div>{{ poem.intro_verse.line_two}}</div><div>{{ poem.intro_verse.line_three}}</div><div>{{ poem.intro_verse.line_four}}</div><div>{{ poem.intro_verse.line_five}}</div></p><p><div>{{ poem.trait_verse.line_one}}</div><div>{{ poem.trait_verse.line_two}}</div><div>{{ poem.trait_verse.line_three}}</div><div>{{ poem.trait_verse.line_four}}</div><div>{{ poem.trait_verse.line_five}}</div></p><p><div>{{ poem.message_verse.line_one}}</div><div>{{ poem.message_verse.line_two}}</div><div>{{ poem.message_verse.line_three}}</div><div>{{ poem.message_verse.line_four}}</div><div>{{ poem.message_verse.line_five}}</div></p><div class="text-center"><a class="btn btn-warning" ui-sref="questionnaire.receiver_name">Restart</a></div></div>'
});
// catch all route
// send users to the receiver_name page
$urlRouterProvider.otherwise('/questionnaire/receiver_name');
Angular controller:
postParams =
{"questionnaire":
{
"receiver_name": $scope.formData.receiver_name,
"receiver_sex": $scope.formData.receiver_sex,
"location": $scope.formData.location,
"relationship": $scope.formData.relationship,
"trait_category": $scope.formData.trait,
"message_category": $scope.formData.message
}
}
// send post request
$http({
method : 'POST',
url : 'api/questionnaire/poem',
data : $.param(postParams), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
})
.success(function(data) {
if (data.success) {
$scope.poem = data.poem;
$scope.formData = {};
$state.go('poem');
}
});
$scope.poem = data.poem' sets the poem data so that {{ poem.title }} and so on get replaced when going to the poem state.

Resources