Do AngularJS controllers use more than one action / configuration method?

Most of the examples of AngularJS controllers I've seen usually have a single action method that works everything for presentation. On the other hand, in controllers using the MVC pattern, and not in AngularJS MVW, there are usually several action methods for each controller, but this is not like AngularJS.

It is provided that any number of methods that execute the behavior can be associated with the number $ (or some other object), but still this is similar to the MVC action methods, since they do not automatically accept direct route input.

I am interested because I am trying to convert an existing ASPP MVC application to angular and I am trying to solve the best organizational failure for controllers.

Are my various assumptions correct?

Do AngularJS controllers use more than one action / configuration method?

Are angular controllers ever broken into separate actions? Or does the angular controller have more or less one action, although routing and presentation may differ?


Update :
The requested example is the AngularJS controller:

myApp.controller('DoubleController', ['$scope', function($scope) {
  $scope.double = function(value) { return value * 2; };
}]);

An example of an Asp.Net MVC controller:

public class CardController : Controller
    {
        private readonly IService _service;

        public CardController(IService service)
        {
            _service = service;
        }

        public ActionResult Index(Guid gameId)
        {
            var model = _service.GenerateCardBuyDisplayModel(gameId);

            return View(model);
        }

        public ActionResult BuyCards(ExecuteBuyModel input)
        {
            _service.ExecuteBuy(input.GameId, input.CardsToBuy);

            return RedirectToAction("Index", "Game", new { id = input.GameId});
        }
    }

Example Ruby on Rails controller:

class ClientsController < ApplicationController
  # This action uses query string parameters because it gets run
  # by an HTTP GET request, but this does not make any difference
  # to the way in which the parameters are accessed. The URL for
  # this action would look like this in order to list activated
  # clients: /clients?status=activated
  def index
    if params[:status] == "activated"
      @clients = Client.activated
    else
      @clients = Client.inactivated
    end
  end

  # This action uses POST parameters. They are most likely coming
  # from an HTML form which the user has submitted. The URL for
  # this RESTful request will be "/clients", and the data will be
  # sent as part of the request body.
  def create
    @client = Client.new(params[:client])
    if @client.save
      redirect_to @client
    else
      # This line overrides the default rendering behavior, which
      # would have been to render the "create" view.
      render "new"
    end
  end
end

, AngularJS /, MVC Asp.net . Ruby of rails , . MVC Asp.net( Ruby on Rails) , MVC. AngularJS , action/constructor, - . , Asp.net MVC , , -. / AngularJS.

+4
1

, , AngularJS , MVC-. , , . , , , , .

angular IRC:

Angular , MVC, Ruby on Rails Asp.net MVC? ?

wafflejock:

barebones - ""

robdubya :

https://gist.github.com/robwormald/bc87cb187e8f96c4e5f0

+1

Source: https://habr.com/ru/post/1539485/


All Articles