Linking model attribute to checkbox in AngularJs

Currently, I am working on assigning tags during post creation. For this purpose, I have set up a Post model with the following structure:

var mongoose = require('mongoose');

var PostsSchema = {
    title: String,
    content: String,
    postedBy: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Users'
    },
    comments: [{
        text: String,
        postedBy: {
            type: mongoose.Schema.Types.ObjectId,
            ref: 'Users'
        },

    }],

    tags: [String]

};

I am in the process of associating checkboxes to the 'tags' array attribute within the Post.

This is how my post router implementation looks like:

///* Create post */
postRouter.route('/').post(function (req, res) {

        mongoose.createConnection('localhost', 'CMS');
        console.log(req.body);

        var post = {
            title: req.body.title,
            content: req.body.content,
            tags: req.body.tags

        };

        if (typeof req.body.title === "undefined" || typeof req.body.content === "undefined")
        {
            res.json({message:"Error"});
        }else
        {
        var newPost = new Posts(post);
        newPost.save(function (err, post) {
            if (err) res.json({message:"Error"});
            res.json(post);
        });
        }

});

The controller associated with this functionality appears as follows:

$scope.createPost = function(post){
        postService.createPost(post);
        postService.getPosts()
            .then(modelPosts);
    }

As for the view template, it is configured as below:

div(ng-controller='postController') 
h2 Create Post
                    form
                        div.form-group
                            label(for='title') Title
                                input(type='text', class='form-control', id='title', name='title', placeholder='Title', ng-model='newpost.title', autofocus)
                        div.form-group
                            label(for='password') Content
                                input(type='text', class='form-control', id='content', name='content', placeholder='content', ng-model='newpost.content')
                    div(ng-controller='tagController')
                        h2 Tags
                        div( ng-model='Tags', ng-init='getTags()')
                            ul( ng-repeat='tag in Tags')
                                li
                                    label
                                        input(ng-model='newpost.tag',value='{{tag.name}}', type='checkbox', name='tag[]')
                                        span {{tag.name}}
                    button( ng-click='createPost(newpost)', class='btn btn-small btn-primary') Create Post

Despite successfully rendering tags and creating checkboxes in the view, there seems to be an issue with the binding. When selecting one checkbox, all checkboxes are getting checked simultaneously.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

jQuery was denied permission to implement inline styling due to non-compliance with the specified Content Security Policy directive

Currently, I am exploring the GitHub project play-silhouette-slick-seed, which serves as an illustration of the Silhouette authentication library for Play Framework in Scala. My goal is to incorporate it into my own project. However, while attempting to ru ...

Unable to include token when making request using ng-token-auth/devise-token-auth

I'm currently following an excellent tutorial that can be accessed at this URL: written by . I am trying to troubleshoot why my request does not include a token in the header when I sign in. User registration works smoothly and adds a new user to t ...

What could be causing the issue of my database updates not reflecting until I manually refresh the

Utilizing angular with MySQL via php has been a challenge for me. Whenever I try to add something to the database, it gets added successfully, but I have to manually refresh the browser to see the updated results. I believe that angular offers great advan ...

The mute feature in Discord.js along with setting up a muterole seems to be malfunctioning and encountering errors

Currently, I am working on implementing a mute command feature. The main goal is to have the bot automatically create a role called Muted if it doesn't already exist, and then overwrite the permissions for every channel to prevent users with that role ...

Ways to steer clear of using eval for converting strings to decimal values

I currently have the fraction "1/7" and I am looking to convert it into a decimal. While I know I can achieve this using eval("1/7"), I prefer not to use eval as it is considered harmful. Are there any alternative methods to accomplish this? ...

Using ASP.NET MVC, pass a list of values separated by commas to an action method

Hey there, I'm facing an issue with an ajax call where I am trying to retrieve values from an html select multiple tag. The problem arises when I attempt to pass these values into my controller as I keep getting a null reference error in my controller ...

Displaying a pop-up window upon clicking on an item in the list view

After creating a list where clicking an item triggers a popup, issues arose when testing on small mobile screens. Many users found themselves accidentally tapping buttons in the popup while trying to view it. What is the most effective way to temporarily ...

What is the reason behind not being able to assign identical names to my SailsJS models and MySQL tables?

Recently diving into Sails JS, I found myself in unfamiliar territory with RESTful APIs. Following the guide, I created a User model to correspond with my existing users table. Adding attributes based on the table's columns was straightforward, and a ...

Order an array in Javascript based on the day of the month

I am trying to create a unique function that changes the order of a string based on the day of the month. For instance, if the input string is "HELLO" and today's date is the 1st of April, the output should be "LHEOL". On the 2nd of April, it should ...

Using jQuery to access a server-side SQL database through PHP

After searching for an example on connecting a client to a server's SQL database using JQuery, AJAX, and PHP, I came across this seemingly well-executed guide: Example Link. All my PHP files and the jQuery library (javascript-1.10.2.min.js) are contai ...

capture the alteration of text within an input field

Currently, I am utilizing the Joomla calendar feature to select a date. The HTML code for this functionality is displayed below. When you click on the image, a calendar will pop up allowing you to choose a date. Once selected, the popup closes and the date ...

"Ways to retrieve an array of dates within a specified range of date and time

I am working with date fields in my project { tripScheduleStartDate: '2018-12-05T18:30:00.000Z', tripScheduleEndDate: '2018-12-07T18:30:00.000Z', } Is there a way to generate a datetime array from the start date to the end date, lik ...

User input determines the path of Iron Route in Meteor

A requirement is to execute a function that prompts the user for input and then navigates to that specified value. For instance, if the inserted value is: https://www.youtube.com/watch?v=_ZiN_NqT-Us The intended destination URL should be: download?u ...

What is the best way to pass a variable to the chrome.tab.create function?

Is there a way to pass a variable to the `chrome.tabs.create` function? I am currently working on setting up event listeners for my anchors, but I am faced with a challenge as I am creating them within a for loop: for (var i = 0; i < links.length; i++) ...

"Troubleshooting the issue of Angular's select binding causing a disruption

The Angular version being used is 1.4.7. Within the model in question, there are two objects: 'systems', which is an array, and 'selectedSystem'. The desired outcome is for 'selectedSystem' to reference one of the objects wit ...

Encountered an issue in Typescript with error TS2554: Was expecting 0 arguments but received 1 when implementing useReducer and useContext in React

I've encountered several errors with my useReducers and useContext in my project. One specific error (TS2554) that I keep running into is related to the AuthReducer functionality. I'm facing the same issue with each Action dispatch. I've tri ...

I'm facing an issue where TailwindCSS fails to stretch my VueJS application to full screen width

My components are all contained within a div with classes flex-row, w-screen, and content-center. However, when I switch to reactive/mobile mode on the browser, it only takes up about 2/3 of the screen and doesn't fill up the remaining space. Below i ...

My attempts to utilize the local storage key have been unsuccessful in storing my todo list. I am uncertain where the issue lies within my code

I've been working on a Todo List with local storage in React, but I'm running into an issue. It seems that my todos aren't getting stored properly and are disappearing every time the page refreshes. I need to figure out what's causing t ...

Angular 2 routing malfunctioning

I'm encountering an issue while setting up routing in my application. The error displayed in the console is as follows: angular2-polyfills.js:138 Error: XHR error (404 Not Found) loading http://localhost:9000/angular2/router.js(…) Below is the co ...

Searching for the index of a nested array in jQuery using JSON

I am currently working on developing an image uploader using Codeigniter3 along with jQuery and Ajax. Problem: I am facing difficulty in understanding how to locate the index of the array received from the ajax response shown below. Here is the data retu ...