我有一个文本框: -
<label>Total Amount</label>
<input type="text" ng-model="totalAmount" disabled="disabled" ng-value="a.one+a.two+a.three+a.four" style="width:150px;height:30px"/>
The ng-value above is a sum of other four textboxes values.
还有其他六个文本框: -
<label>Total Amount</label>
<input type="text" ng-model="b.mul1" ng-value="dividedValue(totalAmount,b.val1)"/>
<label>Total Amount</label>
<input type="text" ng-model="b.val1" ng-value= "dividedValue(totalAmount,b.mul1)"/>
<label>Total Amount</label>
<input type="text" ng-model="b.mul2" ng-value= "dividedValue(totalAmount,b.val2)"/>
<label>Total Amount</label>
<input type="text" ng-model="b.val2" ng-value= "dividedValue(totalAmount,b.mul2)"/>
<label>Total Amount</label>
<input type="text" ng-model="b.mul3" ng-value= "dividedValue(totalAmount,b.val3)"/>
<label>Total Amount</label>
<input type="text" ng-model="b.val3" ng-value= "dividedValue(totalAmount,b.mul3)"/>
我在这里要做的是保持totalAmount
并根据mul
和val
更改进行修复。示例: - totalAmount = mul1*val1, mul1 = totalAmount/val1, val1 = totalAmount/mul1
。
如果用户更改mul1,则val1更改(totalAmount / val1),反之亦然。
在我的指令代码中: -
scope.dividedValue = function(a,b){
return a / b;
}
但是这种方法什么都不返回。任何人都可以告诉我错误。
答案 0 :(得分:0)
你的错误在于函数名称,它必须是“divideValue但它的divisedValue”
答案 1 :(得分:0)
您没有传递正确的值,ng-model
是b.val1
,b.mul1
等等,但您只是在方法中传递了val1
,mul1
调用
<label>Total Amount</label>
<input type="text" ng-model="b.mul1" ng-value="dividedValue(totalAmount,b.val1)"/>
<label>Total Amount</label>
<input type="text" ng-model="b.val1" ng-value= "dividedValue(totalAmount,b.mul1)"/>
<label>Total Amount</label>
<input type="text" ng-model="b.mul2" ng-value= "dividedValue(totalAmount,b.val2)"/>
<label>Total Amount</label>
<input type="text" ng-model="b.val2" ng-value= "dividedValue(totalAmount,b.mul2)"/>
<label>Total Amount</label>
<input type="text" ng-model="b.mul3" ng-value= "dividedValue(totalAmount,b.val3)"/>
<label>Total Amount</label>
<input type="text" ng-model="b.val3" ng-value= "dividedValue(totalAmount,b.mul3)"/>
如上所述,答案更改方法名称,因为有错字
dividedValue(a,b){
return a/b;
}
答案 2 :(得分:0)
您可以尝试以下代码。
boolean VISIBLE_PASSWORD = false; //declare as global variable befor onCreate()
loginPassword = (EditText)findViewById(R.id.loginPassword);
loginPassword.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getRawX() >= (loginPassword.getRight() - loginPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
// your action here
//Helper.toast(LoginActivity.this, "Toggle visibility");
if (VISIBLE_PASSWORD) {
VISIBLE_PASSWORD = false;
loginPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_off_black_24dp, 0);
} else {
VISIBLE_PASSWORD = true;
loginPassword.setInputType(InputType.TYPE_CLASS_TEXT);
loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_black_24dp, 0);
}
return false;
}
}
return false;
}
});