Trying for creating multiple progress bar with dynamic value
<progressbar class="progress-striped active" value="{{getValue(value.currentStatus)}}"
type="{{getType(this.value, value.currentStatus)}}">
{{ value.currentStatus }}
</progressbar>
following two functions are called above, but getType function is called and working
but getValue function is not called its throw error
Error: [$parse:syntax] Syntax Error: Token 'getValue' is unexpected,
expecting [:] at column 3 of the expression
[{{getValue(value.currentStatus)}}] starting at
[getValue(value.currentStatus)}}]
$scope.getValue = function(Status) {
var tasksLength = 4;
var completedActions;
if (Status != null) {
completedActions = completedActions + 1;
}
var progressActions = (completedActions == tasksLength) ? 0 : 1;
var queuedActions = tasksLength - (completedActions + progressActions);
return Math.ceil(((queuedActions * 0.09) + (progressActions * 0.35) +
completedActions) / tasksLength * 100);
}
$scope.getType = function(value, Status) {
if ((value > 80) && (Status == "FAILED")) {
type = 'danger';
} else if (value > 80) {
type = 'success';
} else if (value > 50) {
type = 'warning';
} else {
type = 'info';
}
return type;
}
please help me to solve this error
Related
I am using custom filter for my table content search my custom filter function is
return function(data, search) {
if(angular.isDefined(search)) {
var results = [];
var i;
var searchVal = $filter('lowercase')(search);
for(i = 0; i < data.length; i++){
var name = $filter('lowercase')(data[i].name);
var description = $filter('lowercase')(data[i].description);
if(name.indexOf(searchVal) > -1 || description.indexOf(searchVal) > -1){
results.push(data[i]);
}
}
return results;
} else {
return data;
}
};
when i put any text in search box it will get
TypeError: Cannot read property 'indexOf' of null
if((name !=null && name.indexOf(searchVal) > -1) || (description!=null && description.indexOf(searchVal) > -1)){
results.push(data[i]);
}
name or description is giving null value try above code
Check null condition
return function(data, search) {
if(angular.isDefined(search)) {
var results = [];
var i;
var searchVal = $filter('lowercase')(search);
for(i = 0; i < data.length; i++){
var name = $filter('lowercase')(data[i].name);
var description = $filter('lowercase')(data[i].description);
if(name !== null && description !== null){
if(name.indexOf(searchVal) > -1 || description.indexOf(searchVal) > -1){
results.push(data[i]);
}
}
}
return results;
} else {
return data;
}
};
I have to convert Java code to angularjs ..In java i used while loop for numeric iterator something like below and in angularjs i tried ng-repeat but its not worked as loop sometime increase by +1 or +2 etc.Can someone please guide ho to do numeric iteration in angularjs?
int curretPos = 0;
String namePattern ="SOmeValue";
while (curretPos < namePattern.length()) {
String featureName = "";
if (Constants.namePatternformat.charAt(0) == namePattern.charAt(curretPos)
&& Constants.namePatternformat.charAt(1) == namePattern.charAt(curretPos + 1)) { // name pattern
curretPos = curretPos + 2;
int nextPos = namePattern.indexOf(Constants.namePatternformat.charAt(2), curretPos);
if (nextPos != -1) {
featureName = namePattern.substring(curretPos, nextPos);
curretPos = nextPos;
if (features.containsKey(featureName)) {
name = name.concat(String.valueOf(features.get(featureName)));
} else {
throw SomeException;
}
} else {
throw SomeException;
}
} else if (Constants.namePatternParent.charAt(0) == namePattern.charAt(curretPos)
&& (Character.toLowerCase(Constants.namePatternParent.charAt(1)) == Character.toLowerCase(namePattern.charAt(curretPos + 1)))) { // parent name pattern
if((namePattern.length() - curretPos) >= Constants.namePatternParent.length()) {
if (!Constants.namePatternParent.equals(namePattern.substring(curretPos, (curretPos+Constants.namePatternParent.length())))) {
throw SomeException;
}
}else{
throw SomeException;
}
curretPos = curretPos + (Constants.namePatternParent.length() - 1);
if(null != parent){
name = name.concat(parent);
}
} else if (Constants.namePatternIncrement.charAt(0) == namePattern.charAt(curretPos)
&& (Character.toLowerCase(Constants.namePatternIncrement.charAt(1)) == Character.toLowerCase(namePattern.charAt(curretPos + 1)))) { // increment name pattern
if((namePattern.length() - curretPos) > Constants.namePatternIncrement.length()) {
if (!Constants.namePatternIncrement.substring(0, 5).equals(namePattern.substring(curretPos, curretPos+5))) {
throw SomeException;
}
}else{
throw SomeException;
}
curretPos = curretPos + (Constants.namePatternIncrement.length() - 2) + 1;
int nextPos =
namePattern.indexOf(Constants.namePatternIncrement
.charAt(Constants.namePatternIncrement.length() - 1), curretPos);
if (nextPos != -1) {
featureName = namePattern.substring(curretPos, nextPos);
curretPos = nextPos;
if (features.containsKey(featureName)) {
if (null != features.get(featureName)
&& features.get(featureName).matches("^-?\\d+$")) {
int currentInstance = Integer.valueOf(features.get(featureName)) + (instance-1);
name = name.concat(String.valueOf(currentInstance));
} else {
throw SomeException;
}
} else {
throw SomeException;
}
} else {
throw SomeException;
}
} else {
name = name.concat(String.valueOf(namePattern.charAt(curretPos)));
}
curretPos = curretPos + 1;
}
I am trying to search text on table using angular ..I am able to search text in table .But my search works when I press enter or “search button” .Example when I write “Active” it not show the result but when I press enter or press search button it show the output .can we do the like search like autocomplete .Example when I press “a’ it show all item which start from “a” .Then if user write “ac” then show “ac” value ..same like that .when user write “active “ it show rows which have “active” without using search button or enter .can we make add filter so that it works properly ?
here is my code
$scope.searchInvoices = function(evt, queryval) {
$scope.haveNorecordFound = true;
if (typeof queryval != "undefined" && queryval.length === 0 || evt.keyCode === 13 || evt.type === 'click') {
if (typeof queryval == "undefined" || queryval.length === 0) {
console.log("if===")
isfilterOccured = false;
$scope.tasklist_records = $scope.total_tasklist_records;
$scope.totalNumberOfrecord = $scope.tasklist_records.length + " records found."
} else {
console.log("esle===")
var recordset = $scope.serachObject;
results = [];
var recordsetLength = recordset.length;
var searchVal = queryval.toLowerCase();
var i, j;
for (i = 0; i < recordsetLength; i++) {
var record = recordset[i].columns;
for (j = 0; j < record.length; j++) {
if (record[j].value != null) {
var invoice = record[j].value.toLowerCase();
if (invoice.indexOf(searchVal) >= 0) {
results.push(recordset[i]);
}
}
}
}
var nameOrPathValues = results.map(function(o) {
var result = {};
o.columns.forEach(function(c) {
result[c.fieldNameOrPath] = c.value;
});
return result;
});
console.log("serach");
console.log(nameOrPathValues);
var objectarray = nameOrPathValues.map(function(o) {
var result = {};
collectNameOrPath.forEach(function(name) {
result[name] = o[name];
});
return result;
});
isfilterOccured = true;
$scope.tasklist_records = objectarray;
if ($scope.tasklist_records.length == 0) {
$scope.haveNorecordFound = false;
} else {
$scope.totalNumberOfrecord = $scope.tasklist_records.length + " records found."
}
}
}
};
After debugging in code, I found that you're biding function on either enter button press or search click. That's why it was not working on ng-keyup. Please replace your function from below code.
$scope.searchInvoices = function(evt, queryval) {
console.log(queryval)
$scope.haveNorecordFound = true;
var recordset = $scope.serachObject;
results = [];
var recordsetLength = recordset.length;
var searchVal = queryval.toLowerCase();
var i, j;
for (i = 0; i < recordsetLength; i++) {
var record = recordset[i].columns;
for (j = 0; j < record.length; j++) {
if (record[j].value != null) {
var invoice = record[j].value.toLowerCase();
if (invoice.indexOf(searchVal) >= 0) {
results.push(recordset[i]);
}
}
}
}
var nameOrPathValues = results.map(function(o) {
var result = {};
o.columns.forEach(function(c) {
result[c.fieldNameOrPath] = c.value;
});
return result;
});
console.log("serach");
console.log(nameOrPathValues);
var objectarray = nameOrPathValues.map(function(o) {
var result = {};
collectNameOrPath.forEach(function(name) {
result[name] = o[name];
});
return result;
});
isfilterOccured = true;
$scope.tasklist_records = objectarray;
if ($scope.tasklist_records.length == 0) {
$scope.haveNorecordFound = false;
} else {
$scope.totalNumberOfrecord = $scope.tasklist_records.length + " records found."
}
};
Is there a formal property bag for Angular? I need a way to temporarily store variables and optionally save them between apps.
To save time, I whipped one up. It's here if anyone needs it, however I would love to find one in a framework that is supported by a team:
/**
* Created by Fred Lackey on 4/24/15.
*/
(function (module) {
var propertyBag = function (localStorage) {
var items = [];
var getIndex = function (key) {
if (!key || !key.trim || key.trim().length < 1) { return -1; }
if (items.length < 1) { return -1; }
for (var i = 0; i < items.length; i += 1) {
if (items[i].key.toLowerCase() === key.toLowerCase()) { return i; }
}
return -1;
};
var exists = function (key) {
return (getIndex(key) >= 0);
};
var getItem = function (key) {
var index = getIndex(key);
return (index >= 0) ? items[index] : null;
};
var getValue = function (key) {
var index = getIndex(key);
return (index >= 0) ? items[index].value : null;
};
var putItem = function (key, value) {
if (!key || !key.trim || key.trim().length < 1) { return; }
var index = getIndex(key);
if (index >= 0) {
items[index].value = value;
} else {
items.push({ key: key, value: value });
}
};
var removeItem = function (key) {
var index = getIndex(key);
if (index >= 0) { items.splice(index, 1); }
};
var count = function () {
return items.length;
};
var saveBag = function (key) {
if (!key || !key.trim || key.trim().length < 1) { return; }
localStorage.add(key, items);
};
var loadBag = function (key) {
if (!key || !key.trim || key.trim().length < 1) { return; }
var bag = localStorage.get(key);
if (!bag || !bag.length) { return; }
for (var i = 0; i < bag.length; b += 1) {
if (!bag[i].key || !bag[i].key.trim || bag[i].key.trim().length < 1) { continue; }
putItem(bag[i].key, bag[i].value);
}
localStorage.remove(key);
};
return {
getItem: getItem,
exists: exists,
getValue: getValue,
putItem: putItem,
removeItem: removeItem,
count: count,
save: saveBag,
load: loadBag
};
};
module.factory('propertyBag', propertyBag);
})(angular.module('common'));
Here's the local storage code if you don't already have one (referenced in the code above)...
(function (module) {
var localStorage = function ($window) {
var store = $window.localStorage;
var add = function (key, value) {
value = angular.toJson(value);
store.setItem(key, value);
};
var get = function (key) {
var value = store.getItem(key);
if (value) {
value = angular.fromJson(value);
}
return value;
};
var remove = function (key) {
store.removeItem(key);
};
return {
add: add,
get: get,
remove: remove
}
};
module.factory('localStorage', localStorage);
})(angular.module('common'));
For some reason unknown to me it thinks my array pressed keys is not defined. The error is : "Access of undefined property pressedKeys." But the array works fine in my onKeyDown and Up functions.. Any ideas?
Here is the code:
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var Entities:Array = new Array();
var PressedKeys:Array = new Array();
//Create player ...more code
function onEnterFrame(event:Event):void
{
updateVel();
//...
}
function updateVel()
{
if (pressedKeys[37]) //getting error here
{
// left
player.velX -= player.speed;
}
else if (pressedKeys[65])
{
player.velX -= player.speed;
}
if (pressedKeys[38])
{
// up
player.velY -= player.speed;
}
else if (pressedKeys[87])
{
player.velY -= player.speed;
}
//more code...
}
function onKeyDown(event:KeyboardEvent):void
{
PressedKeys[event.keyCode] = true; //works fine here
trace("Keycode: " + event.keyCode + " is: " + PressedKeys[event.keyCode]);
}
function onKeyUp(event:KeyboardEvent):void
{
PressedKeys[event.keyCode] = false;
trace("Keycode: " + event.keyCode + " is: " + PressedKeys[event.keyCode]);
}
function rand(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
You need to use PressedKeys not pressedKeys - notice the upper/lower case.