Utilize AngularJS to inject a value into the jk-rating-stars element

Hello there, I'm wondering how to assign a value to "rating" attribute as "ctrl.rating" using $scope in AngularJS.

<jk-rating-stars max-rating="5" rating="ctrl.rating"
    read-only="ctrl.readOnly" on-rating="ctrl.onRating(rating)">
</jk-rating-stars>

Thank you!

Answer №1

<div ng-app="myApp" ng-controller="MyCtrl as ctrl">
    <jk-rating-stars max-rating="5" rating="ctrl.rating"
        read-only="ctrl.readOnly" on-rating="ctrl.onRating(rating)">
    </jk-rating-stars>
</div>

Here is the code for initializing Angular and setting up a controller:

angular.module('myApp', ['ngMaterial', 'jkAngularRatingStars'])

.controller('MyCtrl', function() {
    this.rating = 3;
    this.readOnly = false;
    this.onRating = function(rating){
      alert('On Rating: ' + rating);
    };
});

Check out the DEMO here!

This demo includes the necessary script tags and links to external resources:

<script src="//unpkg.com/angular/angular.js"></script>
<script src="//unpkg.com/angular-animate/angular-animate.js"></script>
<script src="//unpkg.com/angular-aria/angular-aria.js"></script>
<script src="https://unpkg.com/angular-material/angular-material.js"></script>
<link rel="stylesheet" href="https://unpkg.com/angular-material/angular-material.css" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://unpkg.com/angular-jk-rating-stars/dist/jk-rating-stars.css" />
<script src="https://unpkg.com/angular-jk-rating-stars/dist/jk-rating-stars.js"></script>

<body ng-app="myApp" ng-controller="MyCtrl as ctrl">
  <jk-rating-stars max-rating="5" rating="ctrl.rating"
      read-only="ctrl.readOnly" on-rating="ctrl.onRating(rating)">
  </jk-rating-stars>
  <br>
  <input type="number" ng-model="ctrl.rating" />
</body>

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

The Datejs library is experiencing issues following an upgrade to jQuery 3.x

I'm currently working on a node.js project that utilizes the Datejs library. However, after updating our local jQuery file from version 1.9.1 to 3.6.0, this library has stopped functioning properly. Here is a snippet of the code: var today = Date ...

Rxjs: Making recursive HTTP requests with a condition-based approach

To obtain a list of records, I use the following command to retrieve a set number of records. For example, in the code snippet below, it fetches 100 records by passing the pageIndex value and increasing it with each request to get the next 100 records: thi ...

Utilize the power of REACT JS to transform a specific segment within a paragraph into a hyperlink. Take advantage of the click event on that hyperlink to execute an API request prior to

In React JSX, I'm encountering an issue trying to dynamically convert a section of text into an anchor tag. Additionally, upon clicking the anchor tag, I need to make an API call before redirecting it to the requested page. Despite my attempts, I have ...

What is the best way to retrieve a message from a resource file using JavaScript?

I have both English and Japanese resource files. When my website switches to Japanese language, I need the messages to display in Japanese just like they do in English. This will require dynamically displaying messages in JavaScript. Thank you. ...

Ensuring the integrity of forms and validating inputs in Angular

Creating a form for adding or editing users has its own set of challenges. When the page loads with existing data in formData, it indicates that an existing user is being edited and the fields need to be populated accordingly. On the other hand, if the pa ...

Execute a jQuery function when the page loads and then trigger it again using buttons

Check out my JSFiddle demonstration here: http://jsfiddle.net/d3fZV/438/ I have a snippet of a slot machine running on a webpage. Currently, it is inactive until the user clicks the button. I am interested in triggering this script on page load or window. ...

Insert the chart into the designated container

Can anyone help me figure out how to place an AmCharts chart into a container and adjust its size accordingly after implementing a drag and drop function? Thanks in advance for any assistance. Here is the link to the fiddle: http://jsfiddle.net/ngg2f5gz/ ...

adding a table using a directive

I'm currently attempting to include a table using a directive in Angular1.3 - controller var studentControllerModule = angular.module('studentDetailApp.controllers', []); /*StudentController: controller for students*/ studentControllerMo ...

How can we ensure that the callback is called only after all functions have completed executing

I am a beginner when it comes to asynchronous programming. I have grasped the concept of using callbacks, but now I find myself needing to execute two functions asynchronously and only call my callback once they both complete: function bigFunction(data, c ...

How can I ensure that my Vue components do not interfere with each other's data when they are

Scenario Consider the following vue component: <template> <div> <slot>{{ title }}</slot> <ul> <li v-for="label in labels" :key="label"> <input type="checkbox ...

The carousel feature in AngularJS's bootstrap is currently experiencing technical difficulties

SOLVED: Look at this Codepen link for the correct code: Codepen Why is my angular bootstrap carousel displaying images stacked on top of each other without sliding? This is how I have set it up: HOME.HTML: <div id="slides_control"> <div> ...

Difficulty encountered while attempting to deploy the front-end on Heroku

I recently completed a typeorm project with the following structure: https://i.stack.imgur.com/ReQK1.png Both the client and root directories contain index files located in the src directory. In the package.json file within the client directory, I made a ...

Is it possible to customize the styling of certain fundamental MUI components using makeStyles?

:D This is my first time embarking on a project from the ground up using react and MUI. I've been curious if I have set it up correctly. My goal right now is to incorporate some styling using makeStyles for certain components provided by Material UI ...

Check a field for validation only when it is visible on the screen

One challenge I'm facing is with an asp.net webform. I have a hidden field that is only displayed when a user selects a radio button. The catch is, this hidden field needs to be mandatory only when it's visible; otherwise, I don't want it to ...

What steps can be taken to get the input type color to function properly in IE-11 in the year 202

Is there a way to get the input type color to function properly in IE as of 2020? <input type="color"> I've experimented with several polyfills, but have not had any success. As a final option, do you have a recommendation for an external libr ...

Struggling with setting values in AngularJS?

Can you assist me in passing data from: (Page 1 -> Module 1 -> Controller 1) to (Page 2 -> Module 2 -> Controller 2) For example: Module reports - Controller ReportsCtrl //Page 1 <html lang="en" class="no-js" ng-app="reports"> <a n ...

Adding methods to a constructor's prototype in JavaScript without explicitly declaring them

In the book Crockford's JavaScript: The Good Parts, there is a code snippet that demonstrates how to enhance the Function prototype: Function.prototype.method = function (name, func) { this.prototype[name] = func; return this; }; Crockford elabo ...

Code written in JavaScript/Node.js with Express can sometimes encounter the issue of functions returning undefined before

Currently, I am facing some difficulties with my module in returning the desired value. The module is designed to search my filesystem and return the most recently created GIF file. If no GIF is found, it looks for a PPM file and then generates a GIF from ...

Is there a way to simulate a minified module for testing purposes?

For my project, I developed a component intended to function as a module. The implementation involves the utilization of third-party code provided in the form of a config file (initOpinionLab.js) and a .min.js file (opinionlab.min.js). As part of the devel ...

The blur event triggers an infinite loop

Within a web form, there is a query that necessitates an answer from the user. Nonetheless, one issue arises with the code provided below: if the user opts to dismiss the alert, it activates the blur event once more, leading to an infinite loop. $('#s ...