Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8362903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:03:00+00:00 2026-06-09T12:03:00+00:00

I am brand new to AngularJS and like what I’ve seen so far, especially

  • 0

I am brand new to AngularJS and like what I’ve seen so far, especially the model / view binding. I’d like to make use of that to construct a simple “add to basket” piece of functionality.

This is my controller so far:

function BasketController($scope) {
    $scope.products = [];

    $scope.AddToBasket = function (Id, name, price, image) {

        ...

    };
}

And this is my HTML:

<a ng-click="AddToBasket('237', 'Laptop', '499.95', '237.png')">Add to basket</a>

Now this works but I highly doubt this is the right way to create a new product object in my model. However this is where my total lack of AngularJS experience comes into play.

If this is not the way to do it, what is best practice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:03:01+00:00Added an answer on June 9, 2026 at 12:03 pm

    You could create a basket service. And generally in JS you use objects instead of lots of parameters.

    Here’s an example: http://jsfiddle.net/2MbZY/

    var app = angular.module('myApp', []);
    
    app.factory('basket', function() {
        var items = [];
        var myBasketService = {};
    
        myBasketService.addItem = function(item) {
            items.push(item);
        };
        myBasketService.removeItem = function(item) {
            var index = items.indexOf(item);
            items.splice(index, 1);
        };
        myBasketService.items = function() {
            return items;
        };
    
        return myBasketService;
    });
    
    function MyCtrl($scope, basket) {
        $scope.newItem = {};
        $scope.basket = basket;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am brand new to the Play framework, but I am trying to use
First I'm brand new to JS but have an idea that object classes are
I'm brand new to Java, programming, and StackOverflow. I need to use a list
I have a brand new database on an ISP which I intend to use
Brand new to CMS: With Joomla or other CMS, If I want to use
I created a brand new project and created a new view controller with a
I'm brand new to OOP and I have a question that's gotta be pretty
I'm brand new to rails, and have inherited an app I'm trying to make
I'm brand new to Android development... coming from iPhone and .Net background. I've seen
Brand new to django. We have a legacy django project using django 0.96x that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.