I'm using a rating in angular. But it happens that I want to create dynamically stars. append the function generated the code that should work the stars. But the stars are not shown I can do?
this is my code: with this i want generate my content dynamic:
angular.module('ionicApp', ['ionic', 'ionic.rating'])
.controller('MyCtrl', function($scope) {
$scope.myTitle = 'IONIC RATINGS DEMO';
$scope.categories = [{
name: "animals",
question: "What do you think about the animals?",
rating: 0
}, {
name: "cars",
question: "What do you think about the cars?",
rating: 0
}, {
name: "flowers",
question: "What do you think about the flowers?",
rating: 0
}];
$scope.rating = {};
$scope.rating.max = 5;
$("#dynamic").append('<rating ng-model="categories[0].rating" max="rating.max"></rating>');
});
<!DOCTYPE html>
<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link href="http://code.ionicframework.com/nightly/css/ionic.min.css" rel="stylesheet">
<script src="http://code.ionicframework.com/nightly/js/ionic.bundle.min.js"></script>
<script src="https://rawgit.com/fraserxu/ionic-rating/master/ionic-rating.js"></script>
<link rel="stylesheet" href="https://rawgit.com/fraserxu/ionic-rating/master/ionic-rating.css">
<script src="script.js"></script>
</head>
<body ng-controller="MyCtrl">
<ion-view>
<h1 class="text-center">{{myTitle}}</h1>
<div class="list">
<div class="item item-button-right" ng-repeat="category in categories">
{{category.question}}
<rating ng-model="category.rating" max="rating.max"></rating>
</div>
</div>
<pre>categories = {{categories|json}}</pre>
<div id='dynamic'></div>
</ion-view>
</body>
</html>
I'm trying to put the star corresponding to the first question.
categories[0].rating //first question
<div id='dynamic'></div> //in this div in my html
$("#dynamic").append('<rating ng-model="categories[0].rating" max="rating.max"></rating>'); //with .append I try...
.append using dynamic content but does not work.nothing appears. What can I do?
Are you looking for something like this:
angular.module('ionicApp', ['ionic', 'ionic.rating']) .controller('MyCtrl', function($scope) { $scope.myTitle = 'IONIC RATINGS DEMO'; $scope.categories = [{ name: "animals", question: "What do you think about the animals?", rating: 2 }, { name: "cars", question: "What do you think about the cars?", rating: 0 }, { name: "flowers", question: "What do you think about the flowers?", rating: 0 }]; $scope.rating = {}; $scope.rating.max = 5; $scope.$watch('categories[0].rating', function() { alert('New value: '+$scope.categories[0].rating); }); })
<html ng-app="ionicApp"> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <link href="http://code.ionicframework.com/nightly/css/ionic.min.css" rel="stylesheet"> <script src="http://code.ionicframework.com/nightly/js/ionic.bundle.min.js"></script> <script src="https://rawgit.com/fraserxu/ionic-rating/master/ionic-rating.js"></script> <link rel="stylesheet" href="https://rawgit.com/fraserxu/ionic-rating/master/ionic-rating.css"> <script src="script.js"></script> </head> <body ng-controller="MyCtrl"> <ion-view> <h1 class="text-center">{{myTitle}}</h1> <div class="list"> <div class="item item-button-right" ng-repeat="category in categories"> {{category.question}} <rating ng-model="category.rating" max="rating.max"></rating> </div> </div> <pre>categories = {{categories|json}}</pre> <div id='dynamic'></div> </ion-view> </body> </html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.