javascript
  • angularjs
  • http
  • 2016-06-29 70 views 0 likes 
    0

    我有這樣一個觀點:Angularjs渲染視圖與範圍值

    <div ng-show=""> 
    <div style='background-color: #13a4d6; border-color: #0F82A8'> 
        {{headerdescription}} 
        <div style='float: right'>{{price}} $</div> 
    </div> 
    <div style=' width: 60%; float: left;'> 
        <div style='padding: 10px;margin-top: 10px;'>{{description}}</div> 
        <div style='padding: 10px;margin-top: 10px;'>{{softvalues}}</div> 
    </div> 
    <div style='float: right; margin-top: 10px;'> 
        <img src='data:image/png;base64,{{image}}'> 
    </div> 
    

    ,我想我在我的角度代碼來獲得這一觀點與設定的範圍值。

    我嘗試這樣做:

    $scope.headerdescription = "YEEES"; 
            $http.get('App_JsQuote/directives/door.html').success(function (html) { 
             console.log(html); 
            }); 
    

    但問題是,範圍值未設置併爲此視圖像以前變得越大。我如何設置範圍值,然後獲取應該在那裏的所有數據的視圖?

    +0

    http://stackoverflow.com/questions/18690804/insert-and-parse-html-into-view-using-angularjs – KreepN

    +0

    您是否使用'ngRoute'或'用戶界面 - router'? –

    +0

    你想要注入html嗎?看起來好像有人寫了一個指令(從URL判斷),在這種情況下,你不會使用'$ http.get',而是使用指令本身。 你的ng-show表達式將對falsy進行評估('ng-show =「」')。 [這是ng-show的plnkr](http://plnkr.co/edit/YgjARFdJOk84PTvOm50C?p=preview) –

    回答

    0

    我不確定,但你可以嘗試這樣的事情嗎?

    $scope.headerdescription = "YEEES";  
    $scope.apply(function() { 
        $http.get('App_JsQuote/directives/door.html').success(function (html) { 
          console.log(html); 
        }); 
    }); 
    
    0

    你可以需要全球範圍內使用ngCloak指令的控制器或元素使用ngBind指令。如果您需要創建媒體或鏈接uri,則需要使用$sce服務。

    例子:

    <div ng-show=""> 
        <div style='background-color: #13a4d6; border-color: #0F82A8'> 
         <span ng-bind="headerdescription"></span> 
        <div style='float: right' ng-bind="price + '$'"></div> 
    </div> 
    <div style=' width: 60%; float: left;'> 
        <div style='padding: 10px;margin-top: 10px;' ng-bind="description"></div> 
        <div style='padding: 10px;margin-top: 10px;' ng-bind="softvalues"></div> 
    </div> 
    <div style='float: right; margin-top: 10px;'> 
        <img ng-src='url'> 
    </div> 
    

    在您的JS文件,你需要使用$ SCE過濾和生成的URL變種。

    例子:

    $scope.url = $sce.trustAsResourceUrl('data:image/png;base64,' + $scope.image); 
    
    相關問題