首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ng-单击inside指令无效。

ng-单击inside指令无效。
EN

Stack Overflow用户
提问于 2016-05-16 10:34:43
回答 1查看 81关注 0票数 1

以下是我的HTML代码:

代码语言:javascript
运行
复制
<section ng-controller="GalleryController as gallery">
    <nav footer-directive></nav>
</section>  

控制员:

代码语言:javascript
运行
复制
angular
    .module('myapp')  
    .controller('GalleryController', GalleryController);

  GalleryController.$inject = ['GalleryService'];

  function GalleryController(GalleryService){
     var self=this;
     self.current_index=0;

     self.leftArrow=function(){
         if (self.photos.length!==0){
           if (self.current_index===0) {
               self.current_index=self.photos.length-1;
           } else {
               self.current_index--;
           }
           self.selected_photo=self.photos[self.current_index];
         }
     };

     self.rightArrow=function(){
         if (self.photos.length!==0){
           if (self.current_index===self.photos.length-1) {
               self.current_index=0;
           } else {
               self.current_index++;
           }
           self.selected_photo=self.photos[self.current_index];
         }
     };

     self.searchResults=function(){
         return GalleryService.getPhotos(self.search_tag,self.page).then(function() {
            self.photos = GalleryService.photos;
            self.selected_photo=self.photos[0];
            var total=GalleryService.total_photos_number;
            self.total_pages=total%15===0 ? total/15 : (total-total%15)/15+1;
         });
     };

     self.searchResults();
  } 

以及指令footerDirective

代码语言:javascript
运行
复制
angular
    .module('myapp')  
    .directive('footerDirective', footerDirective);
function footerDirective(){
     return { 
         link: function(scope,elements,attributes){
                var new_div=document.createElement("div"); 
                new_div.setAttribute("ng-click", "gallery.leftArrow()");
                new_div.innerHTML=content;
                new_div.className=cname;
                elements[0].appendChild(new_div); 

         }
     }
  } 

为什么ng单击不适用于new_div?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-16 10:39:53

使用$compile应该有效

代码语言:javascript
运行
复制
$compile(new_div)(scope)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37251853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档