0

I am trying to get a handle on the best way to do this, so any help would be appreciate.

If you hit this link "/comment/{threadid}+{whatever comment title is}", Sails will go and get the threadID content from the DB. Once it grabs that data, it will send it over to Angular and Angular will display it out.

This is a CRUD application that needs to be a single page application.

Any direction would be helpful as I am not 100% on the flow of the document. I keep getting confused on what router (Angular or Sails) should be taking in the URI.

Thanks!

3 Answers 3

2

Have you tried angular-sails-bind to tie sailsjs models to angular scope models? (https://github.com/diegopamio/angular-sails-bind). I made it for my own project and then decided to put it as a separated library so everybody could benefit and I could have my first experience developing a bower package.

It basically makes a real-time (socket) CRUD for your client that saves and retrieves information automatically from sails models.

I hope it could help you (though it seems that you are using specific controller endpoints).

BTW: it works with sails 0.10 (as some things, like topic names had changed since 0.9). If you need to make it work with 0.9, just let me know and I'll happy to help.

Sign up to request clarification or add additional context in comments.

Comments

0

Sails provides your REST endpoints which your Angular app consumes, otherwise it'll serve up the Angular app and related (possibly static) assets. The Angular app can be served from Sails for any 404 that looks like an html request (in my case this is what happens, but you'll want something more sophisticated if SEO is important).

The Angular app handles routing in the app on the client, including 404/missing routes.

Basically all of the routing a traditional project would handle server-side is now handled in the client with Angular, while the api is served up as JSON from Sails to the client.

You can write tests for your api and the Angular app separately (I used Frisbyjs+Jasmine for the api and Karma/Protractor+Jasmine for the app).

Comments

0

what i am doing is to create Services that retrieve the data then injecting them into the controllers, sails provides by default a Rest api from your created models so if you have a model Employees in sails like this:

module.exports = {
  schema:true,
   attributes: {
      firstName: {
       type: 'STRING',
      },
    }
  }

you can access it by going to

  http://localhost:1337/Employees 

or using angular ngResource in a Service Employees

angular.module('app')
.factory('EmployeesFactory',function($resource){
 return{
   getEmployees:function(searchedName){
      return $resource('http://localhost:1337/Employees',{name:'@id'})
          .query({name:searchedName}).$promise.then(function(response){
              return response;
          });
    },

and in your controller

angular.module('app')
  .controller('EmployeesController',function($scoppe,EmployeesFactory){
        function init(){
         $scope.employees=EmployeesFactory.getEmployees();
       }
       init();
       // or to retrieve a specific employee by name
       $scope.findbyName=function(employeeName){
         $scope.employees=EmployeesFactory.getEmployees(employeeName);
     }

}

hope it helps!

1 Comment

First off, thank you for your assistance and the code source. What I am trying to understand is if there is a way to get around having to hardlink the $resource in the factory. All of the examples that I have seen that are like this, all have the link hardlinked. Also, where do you put the code for services?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.