ga-wdi-exercises / project4

[project]
https://github.com/ga-wdi-exercises/project4
2 stars 8 forks source link

Redirect issues #466

Closed nrc0004 closed 7 years ago

nrc0004 commented 7 years ago

Repo: https://github.com/nrc0004/project4

I am having issues getting my page to refresh when I hit submit on the "add a new blog" form. Here is the relevant code. Also, I should note the addNew function works, I just have to refresh the page manually to get it to show up and I would like it to reload or appear as soon as I hit submit.

.controller ("BlogIndexCtrl",[
    "$state",
    "Blog",
    BlogIndexController
  ])

  .state("BlogIndex", {
    url: '/blogs',
    templateUrl: "/assets/js/ng-views/blog/index.html",
    controller: "BlogIndexCtrl",
    controllerAs: "vm"
  })
function BlogIndexController($state, Blog){
  this.blogs = Blog.query()
  this.newBlog = new Blog()
  this.create = function(){
    this.newBlog.$save().then(function(blog){
      $state.go("BlogIndex", {title: blog.title})
    })
  }
}

Blog Index.html

{{blog.title}}

{{blog.content}}



superbuggy commented 7 years ago

What console error are you getting?

superbuggy commented 7 years ago

function BlogIndexController($state, Blog){
  this.blogs = Blog.query()
  this.newBlog = new Blog()
  this.create = function(){
    this.newBlog.$save().then(function(blog){
      //add a console log (console log blog, dog) here, see if it fires
      $state.go("BlogIndex", {title: blog.title})
    })
  }
}
nrc0004 commented 7 years ago

Nothing >.>

On Apr 5, 2017, at 11:32 AM, James Reichard notifications@github.com wrote:

function BlogIndexController($state, Blog){ this.blogs = Blog.query() this.newBlog = new Blog() this.create = function(){ this.newBlog.$save().then(function(blog){ //add a console log (console log blog, dog) here, see if it fires $state.go("BlogIndex", {title: blog.title}) }) } } — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ga-wdi-exercises/project4/issues/466#issuecomment-291899895, or mute the thread https://github.com/notifications/unsubscribe-auth/AXqfmRI9rRU5cyf64O1-Uq3XAFmdvPn-ks5rs7QSgaJpZM4M0acY.

nrc0004 commented 7 years ago

jk it was just slow— it is saying there is an empty response

POST http://localhost:4000/api/blogs net::ERR_EMPTY_RESPONSE (anonymous) @ angular.js:11630 n @ angular.js:11423 g @ angular.js:11133 (anonymous) @ angular.js:15757 $eval @ angular.js:17025 $digest @ angular.js:16841 $apply @ angular.js:17133 (anonymous) @ angular.js:24813 Pf @ angular.js:3417 d @ angular.js:3405

On Apr 5, 2017, at 11:32 AM, James Reichard notifications@github.com wrote:

function BlogIndexController($state, Blog){ this.blogs = Blog.query() this.newBlog = new Blog() this.create = function(){ this.newBlog.$save().then(function(blog){ //add a console log (console log blog, dog) here, see if it fires $state.go("BlogIndex", {title: blog.title}) }) } } — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ga-wdi-exercises/project4/issues/466#issuecomment-291899895, or mute the thread https://github.com/notifications/unsubscribe-auth/AXqfmRI9rRU5cyf64O1-Uq3XAFmdvPn-ks5rs7QSgaJpZM4M0acY.

superbuggy commented 7 years ago

what response is the back end returning?

nrc0004 commented 7 years ago

[nodemon] restarting due to changes... [nodemon] starting node index.js Listening on 4000 make some programs (node:55075) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html http://mongoosejs.com/docs/promises.html

On Apr 5, 2017, at 12:25 PM, James Reichard notifications@github.com wrote:

what response is the back end returning?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ga-wdi-exercises/project4/issues/466#issuecomment-291916987, or mute the thread https://github.com/notifications/unsubscribe-auth/AXqfmTbuM3y5cw5a8UZ3qkDSNDFEWTXrks5rs8CBgaJpZM4M0acY.

superbuggy commented 7 years ago

You're using Express right? My thought was that the response (most likely res, the local variable in the callback) is sending an empty response.

nrc0004 commented 7 years ago

I am. I'm also no longer receiving any errors, its just not redirecting. It's def capturing the data, it just isnt redirecting/ refreshing the index page so I can immediately see it.

superbuggy commented 7 years ago

what about that console.log from earlier, is that firing?

nrc0004 commented 7 years ago

Its not

nrc0004 commented 7 years ago

Got it! I just took out the state.go (...)and replaced it with $state.current, {}, {reload: true} and it works now. Thanks :)

amaseda commented 7 years ago

:+1: