Miq*_*Ali 7 fancybox angularjs
我已经开始了一个angularjs项目,我想实现fancybox.
为此,我将jQuery和fancybox插件包含在解决方案中.我试图在fancybox窗口中打开下面显示的代码中的模板.
视图
<a href="" ng-click="openPage('popups/add.html')">ADD</a>
调节器
app.controller('MainController',
function MainController($scope) {
$scope.user = "Hey Welcome";
$scope.open = function(template_path){
$.fancybox({"href":template_path})
}
}
)
Run Code Online (Sandbox Code Playgroud)
和popup/add.html
<div class="pop-contnr">
<h2>ADD</h2>
<table>
<thead>
<tr>
<th align=center>{{user}}</th>
</tr>
</thead>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
Fancybox成功打开包含模板的窗口,但{{user}}尚未评估表达式.有人可以帮忙吗?
我为fancybox创建了一个指令
app.directive('fancybox',function($compile, $timeout){
return {
link: function($scope, element, attrs) {
element.fancybox({
hideOnOverlayClick:false,
hideOnContentClick:false,
enableEscapeButton:false,
showNavArrows:false,
onComplete: function(){
$timeout(function(){
$compile($("#fancybox-content"))($scope);
$scope.$apply();
$.fancybox.resize();
})
}
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的团队和我编写的fancybox指令的简化版本,只需单击即可打开基于模板的fancybox.
它在标记中调用,如下所示:
<div fancybox ng-click="openFancybox('templateUrl')"> </div>
Run Code Online (Sandbox Code Playgroud)
该指令的代码是:
app.directive('fancybox', function ($compile, $http) {
return {
restrict: 'A',
controller: function($scope) {
$scope.openFancybox = function (url) {
$http.get(url).then(function(response) {
if (response.status == 200) {
var template = angular.element(response.data);
var compiledTemplate = $compile(template);
compiledTemplate($scope);
$.fancybox.open({ content: template, type: 'html' });
}
});
};
}
};
});
Run Code Online (Sandbox Code Playgroud)
可以看出在这个弹药中工作
| 归档时间: |
|
| 查看次数: |
15669 次 |
| 最近记录: |