mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
BREAKING CHANGE: $ionicScrollDelegate, $ionicSlideBoxDelegate, and
$ionicSideMenuDelegate have been removed.
- $ionicScrollDelegate has been changed to $ionicScrollController.
Documentation:
[ionContent](
http://ajoslin.github.io/docs/nightly/api/directive/ionContent),
[ionScroll](
http://ajoslin.github.io/docs/nightly/api/directive/ionScroll)
Change your code from this:
```html
<ion-content ng-controller="MyCtrl">
<button ng-click="scrollBottom()">Scroll to bottom!</button>
</ion-content>
```
```js
function MyCtrl($scope, $ionicScrollDelegate) {
$scope.scrollBottom = function() {
$ionicScrollDelegate.scrollBottom();
};
}
```
To this:
```html
<!-- optional attr controller-bind, see docs -->
<ion-content ng-controller="MyCtrl">
<button ng-click="scrollBottom()">Scroll to bottom!</button>
</ion-content>
```
```js
function MyCtrl($scope) {
$scope.scrollBottom = function() {
$scope.$ionicScrollController.scrollBottom();
};
}
```
- $ionicSideMenuDelegate has been changed to
$ionicSideMenusController. Documentation:
[ionSideMenus](http://ajoslin.github.io/docs/nightly/api/directive/ionSideMenus)
Change your code from this:
```html
<ion-side-menus>
<ion-side-menu side="left">Side Menu Left</ion-side-menu>
<ion-pane ion-side-menu-content ng-controller="MyCtrl">
<button ng-click="toggleLeftMenu()">
Toggle Left Menu!
</button>
</ion-pane>
</ion-side-menus>
```
```js
function MyCtrl($scope, $ionicSideMenuDelegate) {
$scope.toggleLeftMenu = function() {
$ionicSideMenuDelegate.toggleLeft();
};
}
```
To this:
```html
<!-- optional attr controller-bind, see documentation -->
<ion-side-menus>
<ion-side-menu side="left">Side Menu Left</ion-side-menu>
<ion-pane ion-side-menu-content ng-controller="MyCtrl">
<button ng-click="toggleLeftMenu()">
Toggle Left Menu!
</button>
</ion-pane>
</ion-side-menus>
```
```js
function MyCtrl($scope) {
$scope.toggleLeftMenu = function() {
$scope.$ionicSideMenuController.toggleLeft();
};
}
```
- $ionicSlideBoxDelegate has been removed and upgraded to
$ionicSlideBoxController. It had only one method that
was unneeded. [Documentation](
http://ajoslin.github.io/docs/nightly/api/directive/ionSlideBox)
67 lines
2.4 KiB
JavaScript
67 lines
2.4 KiB
JavaScript
describe('Ionic Content directive', function() {
|
|
var compile, scope;
|
|
|
|
beforeEach(module('ionic'));
|
|
|
|
beforeEach(inject(function($compile, $rootScope, $timeout, $window) {
|
|
compile = $compile;
|
|
scope = $rootScope;
|
|
timeout = $timeout;
|
|
window = $window;
|
|
ionic.Platform.setPlatform('Android');
|
|
}));
|
|
|
|
it('Has $ionicScroll controller', function() {
|
|
var element = compile('<ion-content></ion-content>')(scope);
|
|
expect(element.controller('$ionicScroll').element).toBe(element[0]);
|
|
});
|
|
|
|
it('Has content class', function() {
|
|
var element = compile('<ion-content></ion-content>')(scope);
|
|
expect(element.hasClass('scroll-content')).toBe(true);
|
|
});
|
|
|
|
it('should add padding classname', function() {
|
|
var element = compile('<ion-content padding="shouldPad"></ion-content>')(scope);
|
|
var scrollElement = element.find('.scroll');
|
|
expect(scrollElement.hasClass('padding')).toEqual(false);
|
|
element.scope().$apply('shouldPad = true');
|
|
expect(scrollElement.hasClass('padding')).toEqual(true);
|
|
element.scope().$apply('shouldPad = false');
|
|
expect(scrollElement.hasClass('padding')).toEqual(false);
|
|
});
|
|
|
|
it('Should set start x and y', function() {
|
|
var element = compile('<ion-content start-x="100" start-y="300"></ion-content>')(scope);
|
|
scope.$apply();
|
|
var scrollView = scope.$ionicScrollController.scrollView;
|
|
var vals = scrollView.getValues();
|
|
expect(vals.left).toBe(100);
|
|
expect(vals.top).toBe(300);
|
|
});
|
|
|
|
it('should pass attr.controllerBind ionicScrollController', function() {
|
|
var element = compile('<ion-content controller-bind="scrolly">')(scope);
|
|
scope.$apply();
|
|
expect(scope.scrolly).toBe(element.controller('$ionicScroll'));
|
|
});
|
|
|
|
});
|
|
/* Tests #555 */
|
|
describe('Ionic Content Directive scoping', function() {
|
|
beforeEach(module('ionic', function($controllerProvider) {
|
|
$controllerProvider.register('ContentTestCtrl', function($scope){
|
|
this.$scope = $scope;
|
|
});
|
|
}));
|
|
it('should have same scope as content', inject(function($compile, $rootScope) {
|
|
var element = $compile('<ion-content ng-controller="ContentTestCtrl">' +
|
|
'<form name="myForm"></form>' +
|
|
'</ion-content>')($rootScope.$new());
|
|
var contentScope = element.scope();
|
|
var ctrl = element.data('$ngControllerController');
|
|
expect(contentScope.myForm).toBeTruthy();
|
|
expect(ctrl.$scope.myForm).toBeTruthy();
|
|
}));
|
|
});
|