1

我在角頁上。 第1頁: 在哪個配置是如何在ajax中呈現角模板

.when('/Test/:empId', { 
     templateUrl:'/Templates/test.html', 
     controller: 'TestController' 
    }) 

.when('/Test/:depId', { 
      templateUrl:'/Templates/test1.html', 
      controller: 'Test1Controller' 
     }) 

然後我有另一頁

第2頁: 這頁具有正常MVC剃刀頁按鈕

Button1 

在該按鈕的點擊我想要顯示的模態,其中包含 Page1

所以我寫了

   $.ajax({ 
         url: '/Templates/test.html', 
         type: 'GET', 
         success: function (responce) { 
          var elem = angular.element(responce); 
          $('#testModalBody').html(elem); 
          $('#testModal').modal('show'); 
          //console.log('test responce'); 
         } 
        }); 

我剛開的HTML響應,它不執行「的TestController」 所以變量的作用域沒有得到在聲明的TestController能夠看到數據的HTML頁面的值,而不是。只要看看靜態html模板。

+0

嘗試使用'$編譯(angular.element()($範圍))' –

+0

@JayantPatil:讓angular.element(...)不是一個函數錯誤 –

回答

0

而不是使用$ .ajax,你應該使用Angular JS的$ http服務

而不是像這樣$('#testModalBody'),你可以使用ng-bind-html。

要綁定HTML,請閱讀下面的鏈接。

https://www.w3schools.com/angular/ng_ng-bind-html.asp

+0

我想要保持' testBody'獨立於角度。我想要像部分視圖一樣使用模板。 –

+0

發佈您的完整js代碼。你在哪裏寫了$ ajax代碼在你的文件中? –