我从下拉菜单中选择一个选项。成功调用事件处理程序,其中我使用$ http GET方法异步请求新页面。
<script>
function fun1($scope, $http){
$scope.options="options"
$scope.option1="option1"
$scope.onChangeHandler=function(arg1){
$http({
method: 'GET',
url: "/someurl"
}).then(function successCallBack(responsedata){
$scope.response = responsedata.data
},function errorCallBack(response){
alert("Error!");
});
}
var myApp = angular.module("myApp", [ngSanitize]);
myApp.controller("fun1", fun1);
myApp.config(function($interpolateProvider){
$interpolateProvider.startSymbol("[[")
$interpolateProvider.endSymbol("]]")
});
}
</script>
<body ng-app="myApp" ng-controller="fun1">
<div>
<select class=target id="option" ng-model="options", ng-change="onChangeHandler(options);">
<option ng-model="option1">Option1</option>
</select>
<div id=result ng-bind-html="response"></div>
</div>
</body>
响应页面再次出现了一些角度元素,例如带有ng-repeat等的表格。
<script>
function fun1($scope, $http){
$scope.data=[{name: 'name1', age: 20}, {name: 'name2', age: 25}];
}
var myApp = angular.module("myApp", []);
myApp.controller("fun1", fun1);
myApp.config(function($interpolateProvider){
$interpolateProvider.startSymbol("[[")
$interpolateProvider.endSymbol("]]")
});
</script>
<body ng-app="myApp">
<div ng-controller="fun1">
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="usr in data">
<td>[[usr.name]]</td>
<td>[[usr.age]]</td>
</tr>
</tbody>
</table>
</div>
</body>
使用django渲染方法发送此响应: -
return render(request, someurl.html)
4.Response成功返回,但在目标div中呈现为普通测试。这包括甚至[[**]]角度的表达式如下: -
Name Age
[[usr.name]] [[usr.age]]
Q1。为什么角度不起作用? chrome dev控制台上没有错误,但表中的实际值未填充。我缺少什么概念?
Q2。还有哪些其他选项可以呈现类似于ng-bind-html的角度响应。
答案 0 :(得分:2)
{% verbatim %}
<div ng-app="myApp" ng-controller="myCtrl">
<p>Username is {{ Data.username }}</p>
</div>
{% endverbatim %}
JAVASCRIPT CODE
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$scope.name = "Test"
$http({
method: "GET",
url: url
}).then(function mySucces(response) {
$scope.Data = response.data;
}, function myError(response) {
$scope.Data = response;
});
});
</script>
&#13;