Skip to content

Commit

Permalink
add button
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbingchang committed Mar 16, 2017
1 parent e8f6c69 commit 30784f4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 5 additions & 5 deletions example/app/components/button/button.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

export default class ButtonController {
constructor($state,$timeout,$translate) {
constructor($state, $timeout, $translate) {
'ngInject';
this.$state = $state;
this.disabled = false;
Expand All @@ -15,14 +15,14 @@ export default class ButtonController {
}

sayHello(btn) {
btn.state = {loading: true};
btn.state = { loading: true };
this.tiggleDisabled = false;
this.$timeout(() => {
btn.state = {disabled: false, loading: false};
}, 3000);
btn.state = { disabled: false, loading: false };
}, 3000);
}

$onInit(){
$onInit() {
this.currentLang = this.$translate.use();
}
}
5 changes: 4 additions & 1 deletion lib/Button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export default class Button extends Component {
// call super to update className
super._render();
}

/**
* 包装一个click处理器, 在模板里面用ngClick, 然后调用传进来的处理器
*
Expand All @@ -118,14 +119,16 @@ export default class Button extends Component {
this.click && typeof this.click === 'function'
&& this.click({button: this});
}

/**
* 这里主要是会有Disable值的外部变化
*
* 当组件设置了disable时,会有用到
* @protected
* @param {Object} changeObj
*/
$onChanges(changeObj) {
if (!this._init) return;
console.log(changeObj)
if (changeObj.hasOwnProperty(ButtonState.DISABLED)) {
this._state[ButtonState.DISABLED] = changeObj[ButtonState.DISABLED]['currentValue'];
this._render();
Expand Down
14 changes: 13 additions & 1 deletion lib/Button/button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ describe('Button', () => {
expect(elementDefault.html()).to.contain('disabled="disabled"');
})


it('测试loading 点击', () => {
$rootScope.settingLoading = function (button) {
button.state = { loading: true };
Expand All @@ -130,6 +129,19 @@ describe('Button', () => {

})

it('测试$onchanges', () => {
$rootScope.disabled = false;
let elementDefault = $compile('<f-button disabled="disabled">test</f-button>')($rootScope);
$rootScope.$digest();
let button = new ElementFinder(elementDefault).button();

expect(button.attr('disabled')).to.be.undefined;
$rootScope.disabled = true;
$rootScope.$digest();

expect(button.attr('disabled')).to.be.equal('disabled');
})

})

});

0 comments on commit 30784f4

Please sign in to comment.