无法识别角度JS绑定的HTML函数
Angular JS Bound HTML Functions Not Recognized
我正在编写一个应用程序,它可以绘制数据并以表格的形式显示。Angular JS用于排序和分页。我的分页div是使用Angular中的一个函数注入的,该函数构建一个字符串并将其设置为$scope.pagination变量。问题是,当点击注入的HTML中的ng点击函数时,它们不会被识别。我认为这是因为在呈现页面时它们不在那里。
<html ng-app="listingsApp">
<body ng-controller="pageController" ng-init="type=0">
<div class="pagination" ng-bind-html="paginate"></div>
var listingsApp = angular.module('listingsApp', []);
listingsApp.controller('pageController', function($scope, $sce, $filter, $http) {
$scope.BuildPaginationHtml = function(showPage) {
pageString = "<span class='"paginationItem '" ng-click='"GoToPage(" + i + ")'"> " + i + " </span>";
$scope.pagination = pageString;
}
}
单击此处的跨度不会转到GoToPage功能。我有一个控制台日志来验证它。页面上的所有其他点击事件都可以工作。
对于动态HTML,您必须使用$compile
listingsApp.controller('pageController', function ($scope, $sce, $filter, $http, $compile) {
$scope.BuildPaginationHtml = function(showPage) {
pageString = $compile("<span class='"paginationItem '" ng-click='"GoToPage(" + i + ")'"> " + i + " </span>")($scope);
$scope.pagination = pageString;
}
});
相关文章:
- ng绑定html不工作
- ng使用一个不识别临时变量形式ng repeat的函数绑定html
- ng绑定html,变量名来自ng repeat,但在其他地方定义了变量
- ng使用UI引导指令绑定html
- 自定义绑定 HTML jQuery
- 如何在 ng-repeat 中绑定 html
- 如何在 Angular v1.2 中绑定 HTML
- 如何在angularJS中编写绑定html控件的通用函数
- 当html内容包含使用css加载的图像时,ng绑定html不起作用
- 使用angularjs、jquery、json、ajax基于下拉选择绑定html表数据
- 使用具有全局值的Javascript replace()时,ng绑定html中断
- 不能使用angular.js在视图部分绑定html数据
- 使用angular.js在循环中绑定html内容
- 绑定HTML而不是纯文本
- ng绑定html不'工作不正常
- 从angularjs过滤器输出HTML,无需ng绑定HTML
- js最好的方式绑定HTML字符串在文本区与换行符
- 绑定html表单与XSL动态过滤xml文件
- 用angularjs动态绑定html页面
- 不使用jQuery绑定HTML内容