我已經渲染HTML後使用jQuery的AngularJS調用 後的控制器是渲染angularJS HTML
App.controller('controller', ['$scope', '$http', '$sce', '$routeParams', '$location', function ($scope, $http, $sce, $routeParams, $location) {
$http({
//http call
}).then(function (response) {
$scope.requestpurpose = $sce.trustAsHtml(response.data.requestpurpose);
$scope.$watch('requestpurpose', function(newValue, oldValue) {
if(typeof newValue != 'undefined'){
alert(newValue);
showAlreadySelected();
}
});
}]);
和jQuery腳本是
<script type="text/javascript">
// it will show the div depending on purpose of request
function showAlreadySelected(){
if ($("#1").is(":checked")) {
$("#veterinarian-info").show();
} else {
$("#veterinarian-info").hide();
}
}
</script>
這是我的HTML
<div class="row purpose-box" >
<div class="col-sm-12" ng-bind-html="requestpurpose"></div>
</div>
並在ajax調用下面的HTML是在ng-bind-html renering
<div class="boxes-check">
<div class="box-one">
<input checked="checked" rev="Annual exam" type = "checkbox" name = "request_purpose[]" ng-model=formData.request_purpose[1] onChange="angular.element(this).scope().changePurpose(this)" value = "1" class = "md-check" id = "1" >
</div>
<div class="box-two">
<label title="" for="1">
<span></span>
<span class="check"></span>
<span class="box"></span> Annual exam
</label>
</div>
</div>
<div class="boxes-check">
<div class="box-one">
<input checked="checked" rev="Spay or neuter surgery" type = "checkbox" name = "request_purpose[]" ng-model=formData.request_purpose[2] onChange="angular.element(this).scope().changePurpose(this)" value = "2" class = "md-check" id = "2" >
</div>
<div class="box-two">
<label title="" for="2">
<span></span>
<span class="check"></span>
<span class="box"></span> Spay or neuter surgery
</label>
</div>
</div>
,但我面臨的問題是后角負載其調用showAlreadySelected功能,但不選擇「#1」,一兩件事,如果任何機構可以幫助任何jQuery的功能,這將打擊ID爲「#1,只要輸入元素「,」#2「渲染到我的ng-bind-html div中。
ID不應該以數字,我看到什麼就內檢測的變化是,你設置你的'$ scope.requestpurpose'到HTML字符串,但是你真的把它添加到DOM樹? – ValLeNain
實際上,我只是對舊開發人員構建的舊項目進行了一些更改,所以有一些錯誤是的,它將添加到DOM樹中它的html是
– hu7sy