Javascript AngularJs-带ajax加载的模式窗口
我试图使用ui.bootstrap()为应用程序中的元素启用一个模式窗口弹出窗口,该窗口显示更多信息(包括注释等)。元素在页面上作为一个指令加载,我想我遇到了一个嵌套范围的问题,但是它看起来好像模态窗口正在触发,但什么也没有出现(屏幕淡出) 我的指令如下所示:Javascript AngularJs-带ajax加载的模式窗口,javascript,jquery,ajax,twitter-bootstrap,angularjs,Javascript,Jquery,Ajax,Twitter Bootstrap,Angularjs,我试图使用ui.bootstrap()为应用程序中的元素启用一个模式窗口弹出窗口,该窗口显示更多信息(包括注释等)。元素在页面上作为一个指令加载,我想我遇到了一个嵌套范围的问题,但是它看起来好像模态窗口正在触发,但什么也没有出现(屏幕淡出) 我的指令如下所示: .directive('artifactCause', function() { return { restrict: 'E', replace: true,
.directive('artifactCause', function() {
return {
restrict: 'E',
replace: true,
scope: {
thing: '=thing'
},
templateUrl: 'views/directives/artifact-cause.html',
controller: function($scope, $element, $attrs, $modal) {
console.log('clicked');
$scope.open = function() {
var modalInstance = $modal.open({
backdrop: true,
keyboard: true,
controller: 'artifactModalCtrl',
templateUrl: 'views/directives/modal-artifact.html',
scope: $scope,
resolve: {
thing: function () {
return $scope.thing.cause_id;
}
}
});
};
}
};
});
.controller('artifactModalCtrl', function($scope, $http, loggedStatus, thing) {
var token = loggedStatus.token();
$scope.close = function(result) {
dialog.close(result);
};
$http.get( REQUEST_URL + '/Artifact/ArtifactDetail?token=' + token + '&artifact_id=' + thing ).
success(function(data) {
console.log(data);
$scope.thing = data.response;
return data.response;
}).
error(function(data) {
console.log('Error');
console.log(data);
});
})
templateUrl: 'modal-artifact.html' //this must match the id of your template
artifactModealCtrl控制器如下所示:
.directive('artifactCause', function() {
return {
restrict: 'E',
replace: true,
scope: {
thing: '=thing'
},
templateUrl: 'views/directives/artifact-cause.html',
controller: function($scope, $element, $attrs, $modal) {
console.log('clicked');
$scope.open = function() {
var modalInstance = $modal.open({
backdrop: true,
keyboard: true,
controller: 'artifactModalCtrl',
templateUrl: 'views/directives/modal-artifact.html',
scope: $scope,
resolve: {
thing: function () {
return $scope.thing.cause_id;
}
}
});
};
}
};
});
.controller('artifactModalCtrl', function($scope, $http, loggedStatus, thing) {
var token = loggedStatus.token();
$scope.close = function(result) {
dialog.close(result);
};
$http.get( REQUEST_URL + '/Artifact/ArtifactDetail?token=' + token + '&artifact_id=' + thing ).
success(function(data) {
console.log(data);
$scope.thing = data.response;
return data.response;
}).
error(function(data) {
console.log('Error');
console.log(data);
});
})
templateUrl: 'modal-artifact.html' //this must match the id of your template
我知道我从ajax调用接收到的数据是成功的,因为我可以将其记录到控制台。任何正确方向的见解或指针都将受到极大的赞赏。这很可能是HTML模板找不到的问题。模式正在启动并淡入屏幕,但找不到模板,因此屏幕上没有显示任何内容。
我个人没有成功地在
templateUrl
属性中引用模板的文件位置,因此我所做的是将html模板包含在母版页中,或者任何将触发模式的页面中,如下所示:
<div ng-include src="'../views/directives/modal-artifact.html'">
你是否包含了引导的css?@lucuma是的,我让它在不同的页面上运行,没有任何附加的控制器。你认为这是造型问题吗?我觉得很奇怪,我可以看到元素出现在我的浏览器上,但没有显示在页面上,但是我不确定这是否是JS问题。我有一个类似的问题,这是因为样式。如果模态已附加到文档中,请签入inspectorbody@lort文档正文中添加了两个modal div,但是body标记中没有应用“modal”类,这是您的意思吗?-当调用open函数时,站点灰显(正如它应该的那样),只是没有模式窗口出现。很遗憾,模式HTML似乎缺少勇气:(我试图重现您的错误,但它似乎工作得很好:谢谢您的建议,但我可以通过网络选项卡看到模板正在正确加载。不过想法不错。