Angular code snippets

Well, in fact data comes from a service but filtered with user data at oneController.js

Noted about rootscope

Discussion

Uhm, i think i don't get what's controllerAs

Discussion

<div ng-controller="MainCtrl">
{{ title }}
<div ng-controller="AnotherCtrl">
{{ title }}
<div ng-controller="YetAnotherCtrl">
{{ title }}
</div>
</div>
</div>

Discussion

<div ng-controller="MainCtrl as main">
{{ main.title }}
<div ng-controller="AnotherCtrl as another">
{{ another.title }} {{ main.title }}
<div ng-controller="YetAnotherCtrl as yet">
{{ yet.title }} {{ another.title }} {{ main.title }}
</div>
</div>
</div>

Discussion

So, here you can't access it with AnotherCtrl.title and MainCtrl.title?

Discussion

Btw i think i don't have ng-controller= on my project.. is coded on the routing with controllerAs

Discussion

pranavjindal999 what text-box autocomplete do you recommend (i use angular 1.5.9)? i googled and found several modules like
ng-Autocomplete
(http://ngmodules.org/modules/ngAutocomplete)

md-autocomplete
(https://material.angularjs.org/latest/demo/autocomplete)

auto-complete
(http://jsfiddle.net/sebmade/swfjT/)

Discussion

If I have an object as following

var a = {

    test: {

        test1: {

            test2: 'pranav'

        }

    }

}


and if I want to access
test

of this object using string, I can do as
a["test"]

but if I want to access inner property
a.test.test1

is there any way to do that using string?

Discussion

angular.module('thirdParty', [])
angular.module('thirdParty').controller('test',function(){})


angular.module('mymodule', ['thirdParty'])
angular.module('mymodule').controller('test',function(){})


don't you guys think there should be some namespacing for defining parts of app?

Discussion

Here

mymodule

test controller will overwrite
thirdParty

module's
test

controller

Discussion

The only ways to achieve it is using <router-outlet></router-outlet> inside the app component?

Discussion

In my directive I have this arguments on constructor method:
constructor(private _elementRef: ElementRef)
How can I match this arguments when testing?

import { SidebarDirective } from './sidebar.directive';

describe('SidebarDirective', () => {
it('should create an instance', () => {
const directive = new SidebarDirective();
expect(directive).toBeTruthy();
});
});

Discussion

{
path: 'partner',
loadChildren: 'app/dashboard/dashboard.module#DashboardModule',
canActivate: [Angular2TokenService]
}
in this case should I use CanActivateChild instead?

Discussion

{
"data": [
{
"id": "14",
"waktu": "2017-05-10 09:31:14",
"latitude": "0",
"longitude": "0",
"altitude": "0",
"speedOTG": "0"
},
{
"id": "15",
"waktu": "2017-05-10 09:31:14",
"latitude": "-6.36922",
"longitude": "106.835",
"altitude": "76",
"speedOTG": "10"
},
{
"id": "16",
"waktu": "2017-05-10 09:41:12",
"latitude": "6.0101",
"longitude": "106.123",
"altitude": "75",
"speedOTG": "46"
}
]
}

Discussion

I have an abstract class
abstract class Controller<ab extends Item> {

and much items that implements different Interfaces
class Mail extends Item implements IMail {

i need a method to create an item of the generic type ab from an json object
i tried it like this but it don't work:

var obj = JSON.parse(str);
var item = new ab(obj);


how can i create an object of a generic type?

Discussion

Hello, could anyone help me? I have this error:

Error: $injector:modulerr
Module Error

Discussion

login: function (username, password, callback) { 
db.query('SELECT id, password, expdate FROM users WHERE username=' +
mysql.escape(username) + ';', function (err, rows) {
var row = rows[0];
if (err) console.error(err)
if (!row)
callback(ERR_USER_NOT_FOUND, null);
else
bcrypt.compare(password, row.password, function (err, result) {
if (result){
var expdate = row.expdate;
var currDate = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
if (moment(currDate).isAfter(expdate) && row.id !== 1)
callback ('Please pay your monthly fee to be able to login', null);
else
callback(null, row)
}
else {
callback(ERR_WRONG_PASSWORD, null);
}
})
});
}


This is the function.

Discussion

I didn't get anything except this error (database.js:47) is the function that I wrote up there

TypeError: Cannot read property '0' of undefined
at Query._callback (/home/mikro/www/my_modules/database.js:47:27)
at Query.Sequence.end (/home/mikro/www/node_modules/mysql/lib/protocol/sequences/Sequence.js:86:24)
at /home/mikro/www/node_modules/mysql/lib/protocol/Protocol.js:226:14
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)

Discussion

U can using two ways
1. Using push
path.push(element1)
2. Using parentheses[]
path=[...path,element1]
I hope this help u.

Discussion

santhosh has been warned (1/3)

Discussion

CSS Background URL Problem

I want to have a background image on my div. I have this in my CSS file

url(../../assets/img/home_banner.png


When I build my app using webpack I get a relative URL instead

url(img/home_banner.png)


This does not show the background image. I have googled for a day trying out all the suggested online solutions with no success. I am using AngularJS. I wonder if there is a directive or a webpack hack that can help me deal with this time wasting issue.

My webpack configuration file can be found in this ๐Ÿ‘‡๐Ÿ‘‡Github link.

https://github.com/nkoech/trialscompendium/blob/master/trialscompendium/frontend/webpack.config.js

Discussion

console.log(newStateKitchens.length)

Discussion

I think u need this...

somefunction() {
//body
} //anything.js
<button onclick=somefunction()>blah!</button> //anything.html

Discussion