我有一个脚本将用户重定向到另一个页面.我想在新页面完全加载后将一些内容加载到新页面上的div中.我怎样才能做到这一点.以下不起作用.
function goToPage() {
window.location.href = 'http://www.mypage.com/info;
$('.my_class').load('my/url/path/with/content/to/load');
}
Run Code Online (Sandbox Code Playgroud)
新加载的页面(http://www.mypage.com/info)包含以下div:
<div class="my_class"></div>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我的控制器中有一个如下所示的函数:
AngularJS:
$scope.toggleClass = function(class){
$scope.class = !$scope.class;
}
Run Code Online (Sandbox Code Playgroud)
我希望通过传递我想要切换的类的名称来保持通用性:
<div class="myClass">stuff</div>
<div ng-click="toggleClass(myClass)"></div>
Run Code Online (Sandbox Code Playgroud)
但是myClass没有被传递给角度函数.我怎样才能让它发挥作用?如果我这样编写它,上面的代码是有效的:
$scope.toggleClass = function(){
$scope.myClass = !$scope.myClass;
}
Run Code Online (Sandbox Code Playgroud)
但是,这显然不是一般的.我不想在名为的类中进行硬编码myClass.
我有一个包含ng-repeat指令的页面.在ng-repeat当第一次加载页面,但我希望能够作品使用ng-click刷新的内容ng-repeat.我尝试了以下代码,但它不起作用.有什么建议?
<div ng-click="loadItems('1')">Load 1st set of items</div>
<div ng-click="loadItems('2')">Load 2nd set of items</div>
...
<table>
<tr ng-repeat="item in items">>
// stuff
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
ItemsCtrl:
$scope.loadItems = function (setID) {
$http({
url: 'get-items/'+setID,
method: "POST"
})
.success(function (data, status, headers, config) {
$scope.items = data;
})
.error(function (data, status, headers, config) {
$scope.status = status;
});
};
Run Code Online (Sandbox Code Playgroud)
我希望我的调用loadItems()会导致ng-repeat指令重新加载从我的服务器获得的新数据.