簡體   English   中英

角誤差ng-if

[英]Angular Error ng-if

Angular Js返回此錯誤鏈接

 [1]http://errors.angularjs.org/1.2.10/$parse/lexerr?p0=Unterminated%20quote&p1=s%2013-14%20%5B'%5D&p2=recipe.ID%20!%3D%3D'

我不知道如何應用解決方案。 請幫我。 謝謝我的JavaScript:

var app = angular.module('sample', [])

app.directive("otcDynamic", function ($compile) {// compile Json data return and wrap inside html
    return {
    link: function (scope, element) {
        var template = global.userhtml;
        var linkFn = $compile(template);
        var content = linkFn(scope);
        element.append(content);
     }
   }
});

Web API的Json數據返回

var global {
userhtml ='<table class="recipe-table" cellspacing="0" cellpadding="0"><tbody><tr class="recipe-list" data-ng-repeat="recipe in recipe_data" ng-if="recipe.Keyword == keyw.Keyword" ><td  id="td-img{{recipe.CodeListe}}" rowspan="2"><center><span id="img{{recipe.ID}}X"><a id="{{recipe.ID}}" href="javascript:void(0);"> <img  ng-if="recipe.ID !==''" fallback-src="images/default.png" ng-src="{{recipe.Pictures}}" class="images" id="img{{recipe.ID}}"/><img  ng-if="recipe.Pictures===''" class="images" src="images/default.png" id="img1"/></a></span></center></td><td class="recipes"><div id="drn" class="div-recipe-name"><strong>{{recipe.Name}}</strong></div><br /><div id="drd" class="div-recipe-desc">{{recipe.desc}}</div><div class="div-recipe-allergen">{{recipe.allergen}}</div><div class="div-recipe-cost">{{recipe.cost}}</div></td></tr></tbody></table>' 
}

我的HTML:

  <accordion close-others="false">
  <div>
    <accordion-group class="div-recipe-header">
      <accordion-heading></accordion-heading>
        <my-directive></my-directive>
          <div otc-dynamic></div>   
    </accordion-group>
  </div>
</accordion>

您的網絡api應該返回以下內容:

{ 
  global: {
    userhtml: 'your html code in a string' 
  }
}

但是請注意,您還有其他方法(更好的方法)可以做到這一點。 您可以接收純json數據並使用html模板進行渲染。

還有一件事: global是許多語言和框架中的保留字,它不是變量或哈希鍵的好名字。 考慮將其更改為更合適的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM