AngularJS Drirective Template with variables(dynamic template) - angularjs-directive

Not able to reflect values of the scope variables into
the template of a directive(dash-board-directive). Please help
On Template I have a button and would like to display button color as blue/black/yellow based on the value of scope.btnAttribData(which is holding values data-theme="a"/data-theme="b"/data-theme="e" etc)
/-----------
1)Markup:
Here is how I call my directive:
<div ng-controller="MyDashBoardCtrl">
<dash-board-directive list-item-value="listItemName" items="btnAttribData" ></navtree>
</div>
Where listItemName, and btnAttribData are the parent scope variables(plz refer DashBoardController item#4 ***)
/--------------------------------------
2) Controller on this div : ng-controller="MyDashBoardCtrl" as follows
app.controller('MyDashBoardCtrl', function ($scope)
{
$scope.itemselected = "None";
$scope.organizations={
"kind": "TestData",
"columns":["Row1","Row2","Row3"],
"rows":[
["Yes","No","No"],
["No","Yes","No"],
["No","No","Yes"]
]
};
this.setSelected = function (ID) {
//$scope.itemselected = ID;
$scope.itemselected = ID.btnValue;
}
})
/---------------------
3) code on directivce "dash-board-directive" as follows:
app.directive('dashBoardDirective', function ()
{
return {
template: '<btn-directive ng-repeat="item in items" item="item" itemselected="itemselected" ></navtree-node>',
restrict: 'E',
replace: true,
scope: {
items: '=items', //items holding btnAttribValue ie
//btnAttribValue: '=btnAttribData',
rowItemValue: '=listItemValue',
},
link: function (scope, elem, attrs)
{
}
};
});
app.directive('btnDirective', function ($compile)
{
var btnTemplate = '<button ng-model="tempTheme" >TEST!!!</button>'
return {
restrict: 'E',
require:"^ngController",
scope: {
item: "=",
itemselected: '='
},
compile:function(tElement,tAttrs, transclude)
{
console.log("###---In a linking function directive-btnDirective");
tElement.html(btnTemplate);
return function(scope, element, attrs)
scope.classEnable = scope.item.classEnable; //: "class='ui-disabled'"
scope.tempTheme = scope.item.tempTheme; //: "data-theme=a"
scope.uiBlockValue = scope.item.uiBlockValue; //: "class='ui-block-a'"
if ((angular.isDefined(scope.item)) && (scope.item.length > 0))
{
var btnElement = $compile('<btnDirective items="item"></navtree>')(scope);
elm.append(btnElement);
}
scope.itemSelect = function(id){
//alert(id);
myGreatParentControler.setSelected(id)
}
}
};
});
/---------------
***
4)
listItemName, and btnAttribData are the parent
scope variable from parent controller "DashBoardController" as follows(which stored into an scope.listItemName and scope.btnAttribData on a click event
var app = angular.module('AppDashBoard', [])
app.controller('DashBoardController', function($scope, $window)
{
$scope.listItemName;
$scope.listItemRowDataArray;
$scope.listItemRowDataAttributes={};
$scope.btnAttribData = new Array();
$scope.listItemData={
"kind": "TestData",
"columns":["Row1","Row2","Row3"],
"rows":[
["Yes","No","No"],
["No","Yes","No"],
["No","No","Yes"]
]
};
$scope.listItemClick = function(inputObj){
$scope.listItemName = inputObj;
console.log("### --- $scope.listItemName = "+inputObj )
var colData = $scope.listItemData.columns;
var rowData = $scope.listItemData.rows;
var iColDataIndex = colData.indexOf(inputObj);
var listItemRowData = new Array();
var arrayUiBlock = new Array();
arrayUiBlock[0] = "class='ui-block-a'";
arrayUiBlock[1] = "class='ui-block-b'";
arrayUiBlock[2] = "class='ui-block-c'";
uiBlockCtr=0;
for ( var j = 0; j < rowData[iColDataIndex].length; j++ )
{
var colName = inputObj
var colValue = rowData[iColDataIndex][j];
var tempTheme="";
var btnId = "btnId_"+colName;
var isTempThemeBlue=false;
var classEnable = ""
//$scope.listItemRowDataArray;
listItemRowData.push(colValue);
var buttonAtributes= new Array();
if(colValue=="Yes")
{ buttonAtributes['rowItemValue']=inputObj;
buttonAtributes['btnValue']=colValue;
buttonAtributes['tempTheme']='data-theme="a"';
buttonAtributes['isTempThemeBlue']=true;
buttonAtributes['classEnable']="class='ui-disabled'";
}
else
{
buttonAtributes['rowItemValue']=inputObj;
buttonAtributes['btnValue']=colValue;
buttonAtributes['tempTheme']='data-theme="e"';
buttonAtributes['isTempThemeBlue']=false;
buttonAtributes['classEnable']="class='ui-enable'";
}
if(uiBlockCtr<3)
{
buttonAtributes['uiBlockValue']=arrayUiBlock[uiBlockCtr]
}
else
{ uiBlockCtr=0;
buttonAtributes['uiBlockValue']=arrayUiBlock[uiBlockCtr]
}
uiBlockCtr++;
$scope.btnAttribData.push(buttonAtributes);
}
$scope.listItemRowDataArray=listItemRowData;
};
})
/-------------------
5) index.html as follows:
<!DOCTYPE html>
<html ng-app="AppDashBoard">
<head>
<title>Rating Directive Demo</title>
<link rel="stylesheet" href="rating.css"/>
<link rel="stylesheet" href="vendor/foundation/foundation.min.css"/>
</head>
<body ng-controller="DashBoardController">
<div data-role="page" id="mainPageId">
<div data-role="header" href="" data-role="button" data-theme="b" >
<h1>ListVIEW</h1>
</div>
<div data-role="content" id="mainPageIdContent" >
<div>
<ul data-role="listview" >
<li ng-repeat="item in listItemData.columns">
{{item}}
</li>
</ul>
</div>
</div>
</div>
<div data-role="page" id="listItemDetailPageId">
<div data-role="header" href="" data-role="button" data-theme="b" >
<h1>ListVIEWDetails</h1>
Back
</div>
<div ng-controller="MyDashBoardCtrl">
<dash-board-directive list-item-value="listItemName" items="btnAttribData" ></navtree>
</div>
</div>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<script type="text/javascript" src="rating.js"></script>
</body>
</html>
/-------------------
6) rating.js as follows;
var app = angular.module('AppDashBoard', [])
app.controller('DashBoardController', function($scope, $window)
{
$scope.listItemName;
$scope.listItemRowDataArray;
$scope.listItemRowDataAttributes={};
$scope.btnAttribData = new Array();
$scope.listItemData={
"kind": "TestData",
"columns":["Row1","Row2","Row3"],
"rows":[
["Yes","No","No"],
["No","Yes","No"],
["No","No","Yes"]
]
};
$scope.listItemClick = function(inputObj){
$scope.listItemName = inputObj;
console.log("### --- $scope.listItemName = "+inputObj )
var colData = $scope.listItemData.columns;
var rowData = $scope.listItemData.rows;
var iColDataIndex = colData.indexOf(inputObj);
var listItemRowData = new Array();
var arrayUiBlock = new Array();
arrayUiBlock[0] = "class='ui-block-a'";
arrayUiBlock[1] = "class='ui-block-b'";
arrayUiBlock[2] = "class='ui-block-c'";
uiBlockCtr=0;
for ( var j = 0; j < rowData[iColDataIndex].length; j++ )
{
var colName = inputObj
//arrayColName.push(jsonObjColumn[index]);
var colValue = rowData[iColDataIndex][j];
var tempTheme="";
var btnId = "btnId_"+colName;
var isTempThemeBlue=false;
var classEnable = ""
//for a listItem(Row1), add buttons value to the array "listItemRowData",then, assign this array to
//$scope.listItemRowDataArray;
listItemRowData.push(colValue);
var buttonAtributes= new Array();
if(colValue=="Yes")
{ buttonAtributes['rowItemValue']=inputObj;
buttonAtributes['btnValue']=colValue;
buttonAtributes['tempTheme']='data-theme="a"';
buttonAtributes['isTempThemeBlue']=true;
buttonAtributes['classEnable']="class='ui-disabled'";
}
else
{
buttonAtributes['rowItemValue']=inputObj;
buttonAtributes['btnValue']=colValue;
buttonAtributes['tempTheme']='data-theme="e"';
buttonAtributes['isTempThemeBlue']=false;
buttonAtributes['classEnable']="class='ui-enable'";
}
if(uiBlockCtr<3)
{
buttonAtributes['uiBlockValue']=arrayUiBlock[uiBlockCtr]
}
else
{ uiBlockCtr=0;
buttonAtributes['uiBlockValue']=arrayUiBlock[uiBlockCtr]
}
uiBlockCtr++;
$scope.btnAttribData.push(buttonAtributes);
}
console.log("$scope.btnAttribData");
console.log($scope.btnAttribData)
$scope.listItemRowDataArray=listItemRowData;
console.log("$scope.listItemRowDataArray");
console.log($scope.listItemRowDataArray);
};
})
app.controller('MyDashBoardCtrl', function ($scope)
{
$scope.itemselected = "None";
$scope.organizations={
"kind": "TestData",
"columns":["Row1","Row2","Row3"],
"rows":[
["Yes","No","No"],
["No","Yes","No"],
["No","No","Yes"]
]
};
this.setSelected = function (ID) {
$scope.itemselected = ID.btnValue;
}
})
app.directive('dashBoardDirective', function ()
{
return {
template: '<btn-directive ng-repeat="item in items" item="item" itemselected="itemselected" ></navtree-node>',
restrict: 'E',
replace: true,
scope: {
items: '=items', //items holding btnAttribValue ie
//btnAttribValue: '=btnAttribData',
rowItemValue: '=listItemValue',
},
link: function (scope, elem, attrs)
{
}
};
});
app.directive('btnDirective', function ($compile)
{
var btnTemplate = '<button ng-model="tempTheme" >TEST!!!</button>'
return {
restrict: 'E',
require:"^ngController",
scope: {
item: "=",
itemselected: '='
},
//link: function (scope, elm, attrs, myGreatParentControler) {
compile:function(tElement,tAttrs, transclude)
{
console.log("###---In a linking function directive-btnDirective");
tElement.html(btnTemplate);
return function(scope, element, attrs)
scope.classEnable = scope.item.classEnable; //: "class='ui-disabled'"
scope.tempTheme = scope.item.tempTheme; //: "data-theme=a"
scope.uiBlockValue = scope.item.uiBlockValue; //: "class='ui-block-a'"
console.log("item =", scope.classEnable);
console.log("item =", scope.tempTheme);
console.log("item =", scope.uiBlockValue);
if ((angular.isDefined(scope.item)) && (scope.item.length > 0))
{
var btnElement = $compile('<btnDirective items="item"></navtree>')(scope);
elm.append(btnElement);
}
scope.itemSelect = function(id){
//alert(id);
myGreatParentControler.setSelected(id)
}
}
};
});

Related

calling a controller function - angularjs

Want to call a controller function from a directive tag.
Demo : https://jsfiddle.net/6qqfv61k/
when clicked on 'Export to Excel' i want to call dataToExport() from appCtrl as data is available to export.Any inputs?
html:
<div ng-controller="appCtrl">
</div>
<div excel-export export-data="exportData" file-name="{{fileName}}"></div>
js code:
var app = angular.module('myApp', []);
app.controller('appCtrl', ['$scope', function($scope) {
$scope.dataToExport = function(){
$scope.jsonToExport = [
{
"col1data": "1",
"col2data": "Fight Club",
"col3data": "Brad Pitt"
},
{
"col1data": "2",
"col2data": "Matrix (Series)",
"col3data": "Keanu Reeves"
},
{
"col1data": "3",
"col2data": "V for Vendetta",
"col3data": "Hugo Weaving"
}
];
// Prepare Excel data:
$scope.fileName = "report";
$scope.exportData = [];
// Headers:
$scope.exportData.push(["#", "Movie", "Actor"]);
// Data:
angular.forEach($scope.jsonToExport, function(value, key) {
$scope.exportData.push([value.col1data, value.col2data, value.col3data]);
});
}
}]);
//directive
Use & in the scope option of the directive. & bindings are ideal for binding callback functions to directive. Pass function to the directive as callback
Move the directive inside controller scope
<div ng-controller="appCtrl">
<div excel-export export-data="exportData" file-name="{{fileName}}" call-back="dataToExport()"></div>
</div>
Directive
.directive('excelExport',
function () {
return {
restrict: 'A',
scope: {
fileName: "#",
data: "&exportData",
callBack: "&"
},..
invoke callBack() in the click method of the directive
scope.download = function() {
scope.callBack();
....
}
you can define dataToExport into directives scope function. please take a look
<div ng-controller="appCtrl">
<div excel-export export-data="exportData" export="dataToExport()" file-name="{{fileName}}"></div>
</div>
app
.directive('excelExport',
function () {
return {
restrict: 'A',
scope: {
fileName: "#",
data: "&exportData",
dataToExport: '&export'
},
replace: true,
template: '<button class="btn btn-primary btn-ef btn-ef-3 btn-ef-3c mb-10" ng-click="download()">Export to Excel <i class="fa fa-download"></i></button>',
link: function (scope, element) {
scope.download = function() {
scope.dataToExport();
function datenum(v, date1904) {
if(date1904) v+=1462;
var epoch = Date.parse(v);
return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
};
function getSheet(data, opts) {
var ws = {};
var range = {s: {c:10000000, r:10000000}, e: {c:0, r:0 }};
for(var R = 0; R != data.length; ++R) {
for(var C = 0; C != data[R].length; ++C) {
if(range.s.r > R) range.s.r = R;
if(range.s.c > C) range.s.c = C;
if(range.e.r < R) range.e.r = R;
if(range.e.c < C) range.e.c = C;
var cell = {v: data[R][C] };
if(cell.v == null) continue;
var cell_ref = XLSX.utils.encode_cell({c:C,r:R});
if(typeof cell.v === 'number') cell.t = 'n';
else if(typeof cell.v === 'boolean') cell.t = 'b';
else if(cell.v instanceof Date) {
cell.t = 'n'; cell.z = XLSX.SSF._table[14];
cell.v = datenum(cell.v);
}
else cell.t = 's';
ws[cell_ref] = cell;
}
}
if(range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
return ws;
};
function Workbook() {
if(!(this instanceof Workbook)) return new Workbook();
this.SheetNames = [];
this.Sheets = {};
}
var wb = new Workbook(), ws = getSheet(scope.data());
/* add worksheet to workbook */
wb.SheetNames.push(scope.fileName);
wb.Sheets[scope.fileName] = ws;
var wbout = XLSX.write(wb, {bookType:'xlsx', bookSST:true, type: 'binary'});
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), scope.fileName+'.xlsx');
};
}
};
}
);

Angular bind-html + $sce still remove the inline style

I write simple custom filter that return string value.
The value contain html string and inline style
When binding angular remove the styles
Here is my filter
siteApp.filter('specialText', ['$filter', '$sce', function ($filter, $sce) {
return function (code, items, defaults) {
var out = defaults;
if (items && items.length) {
var arr = $filter('filter')(items, { code: code }, true);
if (arr && arr.length > 0) {
out = arr[0].value;
$sce.trustAsHtml(out);
}
}
return out;
};
}]);
And This is my html
<div ng-bind-html="'body_message' | specialText : specific_texts :''"></div>
The original text contain inline style but angular remove inline style on binding
How can I keep the inline styles
FULL EXAMPLE CODE
<body >
<div ng-app="siteApp">
<div ng-controller="ctrl">
{{'test1' | specialText : arr :'missing....' }}
<div ng-bind-html="'test1' | specialText : arr :'missing....'"></div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-sanitize/1.5.6/angular-sanitize.js"></script>
<script>
var siteApp = angular.module('siteApp', ['ngSanitize']);
siteApp.filter('specialText', ['$filter', '$sce', function ($filter, $sce) {
return function (code, items, defaults) {
var out = defaults;
if (items && items.length) {
var arr = $filter('filter')(items, { code: code }, true);
if (arr && arr.length > 0) {
out = arr[0].value;
$sce.trustAsHtml(out);
}
}
return out;
};
}]);
siteApp.controller('ctrl', ['$scope', function ($scope) {
$scope.arr = [{ "code": "test1", "rte": true, "value": "<p style=\"text-align: left;\">First Row</p>\n<h1 style=\"text-align: center;\">Second Center Row</h1>" }];
}]);
</script>
</body>
You are not using the output of $sce.trustAsHtml(out). Inside your if statement try out = $sce.trustAsHtml(out); and it should be ok.

Test angular directive that adds $parser

I have a directive that validates text to be in a specific format:
angular.module('app')
.directive('validNumber', validNumber);
function validNumber() {
var directive = {
restrict: 'A',
require: '?ngModel',
link: linkFunc
};
return directive;
function linkFunc(scope, element, attrs, ngModelCtrl) {
if (!ngModelCtrl) {
return;
}
ngModelCtrl.$parsers.push(function (val) {
if (angular.isUndefined(val)) {
var val = '';
}
var clean = val.replace(/[^0-9\.]/g, '');
var decimalCheck = clean.split('.');
if (!angular.isUndefined(decimalCheck[1])) {
decimalCheck[1] = decimalCheck[1].slice(0, 2);
clean = decimalCheck[0] + '.' + decimalCheck[1];
}
if (val !== clean) {
ngModelCtrl.$setViewValue(clean);
ngModelCtrl.$render();
}
return clean;
});
element.bind('keypress', function (event) {
if (event.keyCode === 32) {
event.preventDefault();
}
});
}
}
Now I want to test the inner parser function I added and I just can't do it. How can I invoke a call to that function? How can I test the result? My very unsuccessful tests are:
describe('validNumber directive specs', function () {
var scope, compile;
var validHtml = '<form name="testForm"><input name="test" type="text" valid-number ng-model="str" /></form>';
beforeEach(function () {
angular.mock.module('dashboardApp');
module(bootstrapperMock);
inject(function (_$rootScope_, _$compile_) {
scope = _$rootScope_.$new();
compile = _$compile_;
});
});
describe('When a key press occures', function () {
it('should :( ', function () {
scope.str = 0;
var element = compile(validHtml)(scope);
var viewValue = 2, input = element.find('input');
scope.str = viewValue;
scope.$digest();
var e = angular.element.Event('keypress keydown');
e.which = 50;
element.trigger(e);
scope.$digest();
});
});
});
I tried both changing the model and triggering a keypress.
Thanks!
The following works:
describe('When a key press occures', function () {
it('when a key press', function () {
var expected = '';
var element = compile(validHtml)(scope);
element.val('asda');
element.trigger('input');
var actual = element.val();
expect(expected).toBe(actual);
});
});
I also updated the html in this spec:
var validHtml = '<input name="test" type="text" valid-number ng-model="str" />';
The magic here is to trigger 'input' for the element.

Polymer inheritance, parent methods undefined

I am trying to understand how Polymer inheritance works.
I have a parent element fow-filter that contains general filter methods.
<link rel="import" href="../../bower_components/polymer/polymer.html">
<polymer-element name="fow-filter" attributes="">
<template>
<style>
:host {
display: block;
}
</style>
</template>
<script>
(function () {
Polymer("fow-filter",{
created: function(){
console.log("created");
},
ready: function(){
console.log("ready");
},
filterOnRange: function(cardList, key, min, max){
min = parseInt(min);
max = parseInt(max);
if(cardList){
return cardList.filter(
function(card){
return (card[key] >= min) && (card[key] <= max);
}
);
} else {
return [];
}
},
filterOnText: function(cardList, key, filterString, remaining){
if(filterString === "" || filterString === "radio_all"){
return cardList;
}
else if(cardList){
var self = this;
return cardList.filter(
function(card){
//console.log(card);
if( self.strictMatch(card[key], filterString) ){
return true;
} else if(remaining){
remaining.push(card);
}
return false;
}
);
} else {
return [];
}
},
strictMatch: function(text, textToSearch){
if(text && textToSearch){
return ( text.toUpperCase().indexOf(textToSearch.toUpperCase()) > -1 );
} else{
return false;
}
},
fuzzyMatch: function(text, textToSearch){
var search = textToSearch.toUpperCase();
var text = text.toUpperCase();
var j = -1; // remembers position of last found character
// consider each search character one at a time
for (var i = 0; i < search.length; i++) {
var l = search[i];
if (l == ' ') {
continue; // ignore spaces
}
j = text.indexOf(l, j+1); // search for character & update position
if (j == -1) {
return false; // if it's not found, exclude this item
}
}
return true;
}
});
})();
</script>
</polymer-element>
And I have another elements that extends it:
fow-card-filter
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../elements/elements.html">
<polymer-element name="fow-card-filter" attributes="filteredCards cards nameFilter descriptionFilter attributeFilter typeFilter rarityFilter expansionFilter minCost maxCost minCost maxCost minATK maxATK minDEF maxDEF" extends="fow-filter">
<template>
<style>
:host {
display: block;
}
</style>
</template>
<script>
Polymer("fow-card-filter",{
observe: {
"cards nameFilter descriptionFilter attributeFilter typeFilter" : "updateFilteredCards",
"rarityFilter expansionFilter minCost maxCost" : "updateFilteredCards",
"minCost maxCost minATK maxATK minDEF maxDEF" : "updateFilteredCards"
},
created: function (){
this.resetFilters();
},
resetFilters: function(){
this.nameFilter = "";
this.descriptionFilter = "";
this.attributeFilter = "radio_all";
this.typeFilter = "radio_all";
this.rarityFilter = "radio_all";
this.expansionFilter = "radio_all";
this.minCost = "0";
this.maxCost = "20";
this.minATK = "0";
this.maxATK = "10000";
this.minDEF = "0";
this.maxDEF = "10000";
},
updateFilteredCards: function(){
this.filteredCards = this.filterOnText(this.cards, "Name", this.nameFilter);
if(this.descriptionFilter){
this.filteredCards = this.filterOnText(this.filteredCards, "Cardtext", this.descriptionFilter);
}
if(this.attributeFilter){
this.filteredCards = this.filterOnText(this.filteredCards, "Attribute", this.attributeFilter);
}
if(this.rarityFilter){
this.filteredCards = this.filterOnText(this.filteredCards, "Rarity", this.rarityFilter);
}
if(this.expansionFilter){
this.filteredCards = this.filterOnText(this.filteredCards, "Expansion", this.expansionFilter);
}
if(this.typeFilter === "spell"){
//optimize filter
var remainingCards = [];
var spellCards = this.filterOnText(this.filteredCards, "Type", this.typeFilter, remainingCards);
var remainingCards2 = [];
var chantCards = this.filterOnText(remainingCards, "Type", "Chant", remainingCards2);
var istantCards = this.filterOnText(remainingCards2, "Type", "Instant");
this.filteredCards = spellCards.concat(chantCards,istantCards);
} else {
this.filteredCards = this.filterOnText(this.filteredCards, "Type", this.typeFilter);
}
this.filteredCards = this.filterOnRange(this.filteredCards, "Total Cost", this.minCost, this.maxCost);
if((this.typeFilter !== 'spell') && (this.typeFilter !== 'addition')){
this.filteredCards = this.filterOnRange(this.filteredCards, "Total Cost", this.minCost, this.maxCost);
this.filteredCards = this.filterOnRange(this.filteredCards, "ATK", this.minATK, this.maxATK);
this.filteredCards = this.filterOnRange(this.filteredCards, "DEF", this.minDEF, this.maxDEF);
}
}
});
</script>
</polymer-element>
However it seems that my fow-card-filter element does not see its parent methods, every time I call them i get a:
Exception caught during observer callback: TypeError: undefined is not a function
e.g.
this.filteredCards = this.filterOnText(this.cards, "Name", this.nameFilter);
Am I doing something wrong or is there something I am missing about Polymer inheritance?
EDIT:
I don't know why the created and ready methods are called in the parent fow-filter element without first entering the fow-card-filter element ready method.
Calling this.super() in fow-card-filter gives me:
called super() on a method not installed declaratively (has no .nom property)
Eventually I found out that importing the whole elements.html file was wrong.
<link rel="import" href="../../elements/elements.html">
Replacing it with only the parent element solved my problem:
<link rel="import" href="../../elements/fow-filter/fow-filter.html">

Polymer - reload core-list data

I wanted reload a core-list element to show new data, but it´s not refreshing.
I re-call the JS function thats generate the data but doesn t work... and reload like a 'normal' div doesn t work either! The list only shows the new data if i reload the entire page...
function values(sender, textomsg, datacriacao, senderfoto){
var sender2 = sender.split(",");
var textomsg2 = textomsg.split(",");
var datacriacao2 = datacriacao.split(",");
var senderfoto2 = senderfoto.split(",");
var namegen = {
generateString: function (inLength) {
var s = '';
for (var i = 0; i < inLength; i++) {
s += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
}
return s;
},
generateName: function (inMin, inMax) {
return this.generateString(Math.floor(Math.random() * (inMax - inMin + 1) + inMin));
}
};
Polymer('list-test', {
count: sender.length,
ready: function () {
this.data = this.generateData();
},
generateData: function () {
var names = [], data = [];
for (var i = 0; i < this.count; i++) {
names.push(namegen.generateName(4, 8));
}
names.sort();
for (var i = 0; i < this.count; i++) {
data.push({
index: i,
sender: sender2[i],
textomsg: textomsg2[i],
datacriacao: datacriacao2[i],
senderfoto: senderfoto2[i]
});
}
return data;
},
tapAction: function (e) {
console.log('tap', e);
}
});
}
<%----%>
<template id="templateConversas" runat="server">
<div id="item" class="item {{ {selected: selected} | tokenList }}" ><%--onClick="conversa('{{name}}');"--%>
<div class="message" style="background-image: url({{senderfoto}});">
<span class="from"><br/>{{sender}}</span>
<span class="timestamp">{{datacriacao}}</span>
<div class="subject"><br/>{{textomsg}} </div><%--------Infinite List. {{index}}--%>
<%--<div class="body"><br/>Mensagem de teste...........</div>--%>
</div>
</div>
</template>
The problem is also reload the 'list-test'. if i call the js function after the list is loaded it doesn't apply the new data...
Your code isn't complete so it is hard to understand but I think that the problem is that you don't assign the result of the generateData() function to the template's model. Try following script for your component
Polymer('list-test', {
created: function () {
this.data = [];
},
refresh: function () {
this.data = this.generateData();
},
generateData: function () {
// your original code here
}
});
Now the list content should be updated with newly generated data when you call refresh() of the list-test element. To fill the list when element is created add
ready: function () {
this.refresh();
},