无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
Unable To Set Value In data-endVal="{{ucount}}" of CountUp using Angular JS
我正在获取客户和供应商的数量,以便将其显示在仪表板上使用countUp.js作为计数器。
使用的文件
AngularJS v1.3.15countUp.jshttps://github.com/inorganik/countUp.js1.1.1
CountUp 1.1.1 的精简版
控制器代码
myApp.controller('dashboardCtrl', [
'$scope',
'files',
'$http',
function ($scope, files,$http) {
$http.get('../../../Admin/Notification/GetAllNotifications')
.success(function (data, status, headers, config) {
$scope.ucount = parseInt(data['ucount']);
$scope.scount = parseInt(data['scount']);
//alert($scope.ucount);
//alert($scope.scount);
}).
error(function (data, status, headers, config) {
console.log(status);
});
}
])
从GetAllNotifications 生成的JsonResult
{"ucount":3,"scount":2}
显示数据的分区
<div class="col-lg-3 col-sm-6">
<div class="info_box_var_1 box_bg_a">
<div class="info_box_body">
<span class="info_box_icon icon_group"></span>
<span class="countUpMe" data-endVal="1300">1300</span>
</div>
<div class="info_box_footer">
Total Customers
</div>
</div>
</div>
上面的代码非常适用于静态数据,但当我使用{{ucount}}在数据endVal属性中,它在控制台中给出错误:"countUp错误:startVal或endVal不是数字"
可能出现错误,因为get请求是异步的,并且在尝试访问时$scope.ucount不存在?是否尝试设置$scope.ucount的初始值?如0,例如
我初始化了状态中的数据,现在它正在工作这是国家代码
myApp.state("auth.home", {
// this state page title
page_title: 'Stock Management - Dashboard',
// this state url
url: "/",
templateUrl: '../../../Admin/Page/getPage?path=Views/templateviews/dashboard.cshtml',
// load state specific js/css
resolve: {
notificationdetail: function ($http) {
return $http({ method: 'GET', url: '../../../Admin/Notification/GetAllNotifications' })
.then(function (data) {
var notificationdetail = data.data;
return notificationdetail;
});
},
files: [
'uiLoad',
function (uiLoad) {
return uiLoad.load([
// countUp animation
'../../../Areas/Admin/assets/js/countUp.min.js',
]);
}
]
},
controller: 'dashboardCtrl',
ncyBreadcrumb: {
label: 'Home'
}
})
这就是现在的控制器代码
myApp.controller('dashboardCtrl', [
'$scope',
'files',
'$http',
'notificationdetail',
function ($scope, files, $http, notificationdetail) {
$scope.ucount = parseInt(notificationdetail['ucount']);
$scope.scount = parseInt(notificationdetail['scount']);
//// run scripts after state load
$scope.$on('$stateChangeSuccess', function () {
// init dashboard functions
$scope.$watch('countries_data', function () {
countries_data = $scope.countries_data;
yukon_dashboard.init();
});
})
}])
ui代码
<div class="col-lg-2 col-sm-6">
<div class="info_box_var_1 box_bg_a">
<div id="notficDiv" class="info_box_body">
<span class="info_box_icon icon_group"></span>
<span class="countUpMe" data-endval="{{ucount}}">{{ucount}}</span>
</div>
<div class="info_box_footer">
Total Customers
</div>
</div>
</div>
我认为问题在于如何将{{count}}传递给指令。你可能没有正确通过。因为你可能发送的不是一个数字,而是一个字符串。尝试使用:
<span class="countUpMe" count-up end-val={{count}}>...</span>
相关文章:
- Angular JS IE9 Hashbang url rewriting
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 在自定义mean.io包中使用angular-chart.js作为依赖项
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 使用angular重定向到html页面
- angular.js没有'无法在PhoneGap中处理视图标记
- Javascript(Angular)从一个对象数组到第二个数组查找值
- angular 1.5应用程序中的导航栏
- angular的下拉菜单
- Angular只从数组中获取所需的数据
- 如何将不可变的js导入angular 2(alpha)
- Angular js-返回一个包含类似
- 如何使用 Angular JS 将数据保存在数据库中
- 将JSON对象传递给angular指令
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- Angular:更新一次性绑定的数据
- 同步调用,直到用户通过angular验证为访问者
- 将Angular js与taglib结合使用
- 在Angular Fullstack中设置TinyMCE
- 可以't使用Angular解析/检索JSON