Alright my AngularJS Mates.. I need saving. The following is my code. As you can see i'm trying to like pass the firebase data through states, unfortunately 'Offer' is only displaying as '[]' I think this is because i'm using a $firebaseObject, but i just cant crack this code...
(yeah I totally stole a part of this from Codepen)
Legit i would get your address and send you roses if you fixed this for me.
My Factory:
.factory('PetService', function ($firebaseArray, $firebaseObject) {
var ref = new Firebase("https://idargo.firebaseio.com/userData")
var offer = ref.child('Offer');
var pets = [];
for (var i=0; i<100; i++) {
pets[i] = {
id: i,
'Name': 'Name' + i,
'Offer': $firebaseObject(offer)
};
}
return {
all: function () {
return pets;
},
get: function (petId) {
return pets[petId];
}
};
})
DashCtrl:
.controller('DashCtrl', function($scope, $state, $stateParams, PetService) {
$scope.pets = PetService.all();
})
ProfileCtrl:
.controller('ProfileCtrl', function($stateParams, PetService) {
$scope.pet = PetService.get($stateParams.petsId);
})
The State:
.state('app.profile', {
url: "/profile/:petsId",
views: {
'menuContent': {
templateUrl: "routes/profile.html",
controller: 'ProfileCtrl',
}
}
})
The Collection-Repeat:
<div class="col" collection-repeat="pet in pets" item-width="45%" item-height="35%" ui-sref="app.profile({petsId: pet.id })">
The Profile Html:
<div ng-cloak>
<ion-view title="{{pet.id}}">
<div class="bar bar-header loginbar">
<button class="button button-icon ion-ios-arrow-left loginhead" ui-sref="app.dash"></button>
<h1 class="title"></h1>
</div>
<ion-content>
<div>
<center>
<div class="top2">
<div class="wrapperinv">
<div style="padding-top: 15%"></div>
<div class="numberCircle">
<div class="height_fix"></div>
<div class="content"><img src="{{pet.Image}}" class="invoiceimage"></div>
</div>
<div style="margin-top: -100px;"></div>
<div class="mincirc">
<div style="margin-top: 8px;"></div>
<div class="rotate"><i class="icon ion-ios-telephone-outline invi"></i></div>
</div>
<div class="mincirc2" ui-sref="app.chat">
<div style="margin-top: 8px;"></div>
<div class="rotate"><i class="icon ion-ios-chatbubble-outline invi" ></i></div>
</div>
<div style="margin-top: 100px;"></div>
<label class="sometext">{{pet.firstName}}</label>
<div style="margin-top: -50px;"></div>
<h3>
<i class="ion-star invstar invi"></i> <i class="ion-star invstar invi"></i>
<i class="ion-star invstar invi"></i> <i class="ion-star invstar invi"></i>
<i class="ion-star invstar invi"></i>
</h3>
</div>
</div>
</div>
</center>
<div style="margin-top: -10px;"></div>
<div class="list" >
<label class="item item-icon-left">
<i class="icon ion-earth"></i>
<h4 class="invf">Location</h4>
<div class="invtext">{{pet.Name}}</div>
</label>
<label class="item item-icon-left">
<i class="icon ion-calendar"></i>
<h4 class="invf">Age</h4>
<div class="invtext">{{pet.Age}}</div>
</label>
<label class="item item-icon-left" style="word-wrap: break-word; width: 350px;">
<i class="icon ion-person"></i>
<h4 class="invf">About me</h4>
<div class="invtext" >{{item.About}}</div>
</label>
<label class="item item-icon-left">
<i class="icon ion-pizza"></i>
<h4 class="invf" >What I offer</h4>
<div class="invtext">{{pet.Offer}}</div>
</label>
<label class="item item-icon-left">
<i class="icon ion-cash"></i>
<h4 class="invf">Rate</h4>
<div class="invtext">{{item.Rate}}</div>
</label>
</div>
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d150038.30908416258!2d-74.00164182706976!3d40.64734690331712!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89c24fa5d33f083b%3A0xc80b8f06e177fe62!2sNew+York%2C+NY%2C+USA!5e1!3m2!1sen!2sau!4v1440975673055" width="400" height="300" frameborder="0" style="border:0"></iframe>
<button class="button button-block invbut" ng-click="invoice()">
Book With {{item.Name}}
</button>
</div>
</div>
</ion-content>
</ion-view>
</div>
Thanks in advance!
-Sorry if my English is bad... i'm from Australia.
Related
on clicking a button I call viewJob function and pass jobId , the response data I am trying to display in bootstrap modal. But I am unable to do it ,the values are assigning as local variable.
Even I tried this in html
{{viewJob(model.citynew)}}
If still you want that as $scope function then try below code:
Controller:
$scope.model = {}
$scope.viewJob = function (jobId) {
UserService.employerJob(jobId).then(function(response) {
if(response.json.response.statuscode == 0) {
$scope.data = response.json.response.data;
$scope.keyskills = $scope.data.keySkill;
$scope.model.citynew = $scope.data.location.city;
$scope.model.numberofpositionsnew = $scope.data.numberOfPositions;
$scope.model.experiencelevelnew = $scope.data.experienceLevel;
$scope.model.link = $scope.data.link;
$('#viewJobModal1').modal('show');
}
});
};
HTML
<div class="modal fade" id="viewJobModal1" role="dialog" tabindex="-1" aria-hidden="true">
<div class="modal-dialog" role="dialog">
<div class="modal-content" id="style-4" style="height:400px;line-height: 1.8;overflow-y: auto;">
<div class="modal-header" style="background-color:#3e79b6;height:50px;">
<div class="col-sm-4" style="font-size:20px;text-align:center;color:white; width: 94.333333% !important;">View Details of Job</div>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true" style="color:black;">×</span>
</button>
</div>
<div class="modal-body" style="height: 400px;line-height: 1.8;">
<div class="col-lg-12">
<div class="col-lg-12" align="center" style="text-align:justify;">
<div class="col-lg-5"><b>Company Name :</b></div>
<div class="col-lg-7" style="text-align:justify;">{{(model.companynew)}}</div>
</div>
<div class="col-lg-12" align="center" style="text-align:justify;">
<div class="col-lg-5"><b>Job title :</b></div>
<div class="col-lg-7" style="text-align:justify;">{{model.jobtitlenew}}</div>
</div>
<div class="col-lg-12" align="center" style="text-align:justify;">
<div class="col-lg-5"><b>Job Description :</b></div>
<div class="col-lg-7" style="text-align:justify;">{{model.jobdescriptionnew}}</div>
</div>
</div>
</div>
</div>
</div>
</div>
I don't think you can use {{viewJob(model.citynew)}} because viewJob takes a jobId as parameter.
It's generally recommended to resolve promises as part of the transition when opening a modal, by passing them in the resolves block.
E.g. Calling the modal in your page's controller
$modal.open({
templateUrl: 'path/to/modal/template.html',
controller: 'ModalCtrl',
controllerAs: 'modalCtrl',
resolve: {
job: function () {
return UserService.employerJob(jobId);
}
}
});
Then, in your ModalCtrl, you can grab the job as a dependency display the data however you want in your template
angular.module('AppModule').controller('ModalCtrl', ['job', function (job) {
modalCtrl = this;
modalCtrl.keyskills = job.keySkill;
modalCtrl.citynew = job.location.city;
modalCtrl.numberofpositionsnew = job.numberOfPositions;
modalCtrl.experiencelevelnew = job.experienceLevel;
modalCtrl.companynew = job.company;
modalCtrl.jobtitlenew = job.jobTitle;
modalCtrl.jobdescriptionnew = job.jobDescription;
modalCtrl.link = job.link;
}]);
And then display these in your modal template
<div class="modal fade" id="viewJobModal1" role="dialog" tabindex="-1" aria-hidden="true">
<div class="modal-dialog" role="dialog">
<div class="modal-content" id="style-4" style="height:400px;line-height: 1.8;overflow-y: auto;">
<div class="modal-header" style="background-color:#3e79b6;height:50px;">
<div class="col-sm-4" style="font-size:20px;text-align:center;color:white; width: 94.333333% !important;">View Details of Job</div>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true" style="color:black;">×</span>
</button>
</div>
<div class="modal-body" style="height: 400px;line-height: 1.8;">
<div class="col-lg-12">
<div class="col-lg-12" align="center" style="text-align:justify;">
<div class="col-lg-5"><b>Company Name :</b></div>
<div class="col-lg-7" style="text-align:justify;">{{(modalCtrl.companynew)}}</div>
</div>
<div class="col-lg-12" align="center" style="text-align:justify;">
<div class="col-lg-5"><b>Job title :</b></div>
<div class="col-lg-7" style="text-align:justify;">{{modalCtrl.jobtitlenew}}</div>
</div>
<div class="col-lg-12" align="center" style="text-align:justify;">
<div class="col-lg-5"><b>Job Description :</b></div>
<div class="col-lg-7" style="text-align:justify;">{{modalCtrl.jobdescriptionnew}} </div>
</div>
</div>
</div>
</div>
</div>
</div>
Hope that helps :)
I have a problem with the repository list in the list of all Conributors for this repository.
I want to create a Contributors list in the list of repositories downloaded using GitHub Api. However, I can not get these data for each repository and put them in html.
Has anyone any idea how to do this?
Thank you in advance for your help
My code:
App in html
<div ng-controller="gitApi" ng-app="app">
<div class="container">
<h1 class="text-center">
<span ng-hide="userData" />Loading</span>
<span />{{userData.name}}</span>
<br>
<a href="{{userData.html_url}}" class="btn btn-default">
{{userData.login}}
</a>
</h1>
<div class="panel panel-default">
<div class="panel-heading">
<form class="form-inline">
<span>
<h4>Repos <span class="badge">{{repoData.length}}</span>
<input ng-model="searchText" placeholder="Search" class="form-control input-sm">
</h4>
</span>
</form>
</div>
<div class="panel-body">
<div class="list-group">
<div ng-repeat="orgs in orgsData | filter:searchText | orderBy:predicate:reverse" class="list-group-item ">
<div class="row">
<div class="col-md-6">
<h4>
<a href="{{repo.html_url}}" target="_blank">
{{orgs.name}}
</a>
<small>{{orgs.description}}</small>
</h4>
<small>
<a href="{{orgs.homepage}}" class="">
<i class="fa fa-link"></i> WebPage
</a>
</small>
</div>
<div class="col-md-6">
Conributors List:
<div ng-repeat=" | filter:searchText | orderBy:predicate:reverse" class="list-group-item ">
<div class="row">
<div class="col-md-12">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
APP.js
angular.module('app', [])
.controller('gitApi', ['$scope', '$http', function($scope, $http) {
$scope.reposLoaded = false;
$scope.userLoaded = false;
$scope.orgsLoaded = false;
$http.get("https://api.github.com/users/angular")
.success(function(data) {
$scope.userData = data;
loadOrgsRepos();
});
var loadOrgsRepos = function() {
$http.get("https://api.github.com/orgs/angular/repos")
.success(function(data) {
$scope.orgsData = data;
});
}
$scope.predicate = '-updated_at';
}]);
You can get all contributors url from contributors_url and make an API call for each one of these, storing the result in the original $scope.orgsData array :
"use strict";
var githubApp = angular.module('app', []);
githubApp.controller('gitApi', ['$scope', '$http', '$q', function($scope, $http, $q) {
$http.get("https://api.github.com/users/angular")
.success(function(data) {
$scope.userData = data;
loadOrgsRepos();
});
var loadOrgsRepos = function() {
$http.get("https://api.github.com/orgs/angular/repos")
.success(function(data) {
$scope.orgsData = data;
var contribs = [];
for (var i in data) {
contribs.push(data[i].contributors_url);
}
$q.all(contribs.map(function(item) {
return $http({
method: 'GET',
url: item
});
}))
.then(function(results) {
results.forEach(function(val, i) {
$scope.orgsData[i].contributors = val.data;
});
});
});
}
$scope.repo_sort = '-updated_at';
$scope.contrib_sort = '-contributions'
}]);
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body id="page-top" class="index">
<div ng-controller="gitApi" ng-app="app">
<div class="container">
<h1 class="text-center">
<span ng-hide="userData">Loading</span>
<span>{{userData.name}}</span>
<br>
<a href="{{userData.html_url}}" class="btn btn-default">
{{userData.login}}
</a>
</h1>
<div class="panel panel-default">
<div class="panel-heading">
<form class="form-inline">
<span>
<h4>Repos <span class="badge">{{repoData.length}}</span>
<input ng-model="searchText" placeholder="Search" class="form-control input-sm">
</h4>
</span>
</form>
</div>
<div class="panel-body">
<div class="list-group">
<div ng-repeat="orgs in orgsData | filter:searchText | orderBy:repo_sort:reverse" class="list-group-item ">
<div class="row">
<div class="col-md-8">
<h4>
<a href="{{repo.html_url}}" target="_blank">
{{orgs.name}}
</a>
<small>{{orgs.description}}</small>
</h4>
<small>
<a href="{{orgs.homepage}}" class="">
<i class="fa fa-link"></i> WebPage
</a>
</small>
</div>
<div class="col-md-6">
Conributors List:
<div class="list-group-item">
<div class="row">
<div class="col-md-4">
name
</div>
<div class="col-md-4">
avatar
</div>
<div class="col-md-4">
contributions
</div>
</div>
</div>
<div ng-repeat="contrib in orgs.contributors | filter:searchText | orderBy:contrib_sort:reverse" class="list-group-item">
<div class="row">
<div class="col-md-4">
<a href="{{contrib.html_url}}" target="_blank">
{{contrib.login}}
</a>
</div>
<div class="col-md-4">
<img ng-src="{{contrib.avatar_url}}" height="42" width="42" />
</div>
<div class="col-md-4">
<p>
{{contrib.contributions}}
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
Here is another fiddle
I am working with Ionic framework.
I've got two templates both of which use the same "ListController" controller:
1) A list of products.
2) A detailed view of a specific product.
Both templates have a counter field which should be updated when user adds or removes products.
On the header I have a counter for the sum of all products.
What I need is to automatically be updated the fields(specific product counter, total counter) in two templates. When I say automatically I mean when the user adds products in the first template then these should be updated to the second one.
Here's my first template:
<ion-list>
<ion-item class="noPadding" ng-repeat="item in meatTypes" href="#/{{item.imgname}}">
<div class="row counterLine relative noPadding">
<img class="counterBg" src="img/counter.png" alt="pansetes" align="right"/>
<span class="itemCounter" id="product_{{item.id}}">0</span>
</div>
<div class="row">
<div class="col relative">
<img class="itemImg" src="img/{{item.imgname}}.png" alt="pansetes"/>
</div>
<div class="col relative">
<ul class="centerize">
<li class="itemTitle ">{{item.name}}</li>
<li class="itemSubtitle">{{item.subname}}</li>
</ul>
</div>
<div class="col relative">
<ul class="centerize">
<li class="itemPrice">{{item.price}}€</li>
<li class="itemDiscount">{{item.productdiscount}}%</li>
</ul>
</div>
<div class="col relative">
<button class="addMore centerize" id="addMore" onclick="return false">+</button>
</div>
</div>
</ion-item>
</ion-list>
Here's my second template:
<ion-list>
<ion-item class="noPadding" ng-repeat="item in meatTypes | filter: {imgname : whichproduct}">
<div class="row noPadding">
<div class="col col-20 noPadding item-text-wrap">
<p class="expires">
Κατανάλωση εντός </br> <strong>4</strong> </br>Hμερών.
</p>
</div>
<div class="col noPadding col-60">
<img class="detailsImg" src="/img/{{item.imgname}}.png" alt="{{item.name}}"/>
</div>
<div class="col col-20 noPadding">
<div class="row noPadding">
<div class="col noPadding">
<img class="detailsCounterBg" src="img/counter.png" alt="pansetes" align="right"/>
<span class="itemCounter" id="detailsCounter">{{counters[item.id]}}</span>
</div>
</div>
<div class="row noPadding">
<div class="col noPadding">
<ul>
<li><button class="addMore" id="addMore">+</button></li>
<li><button class="addMore" id="subMore">-</button></li>
</ul>
</div>
</div>
</div>
</div>
</ion-item>
</ion-list>
And here's my app.js router and controller:
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('list')
$stateProvider
.state('list', {
url: '/list',
templateUrl: '/templates/product-list.html'
})
$stateProvider
.state('details', {
url: '/:aId',
templateUrl: '/templates/detail.html',
controller: "ListController"
})
})
.controller('ListController',function($scope, $http, $state){
$http.get('js/data.json').success(function(data){
$scope.meatTypes = data;
$scope.whichproduct = $state.params.aId;
$scope.total = $('#totalCounter').html();
$scope.counters = [];
$(".itemCounter").each(function(){
$scope.counters.push($(this).text());
});
});
});
For now I have found a permanent solution as you can see in my controller but I think it misses something.
here's a :screenshot
I have this directive
app.directive('fancybox', function($compile, $timeout){
return {
link: function($scope, element, attrs){
$(element).fancybox({
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'width': '250',
'height': '250',
'speedIn': 600,
'speedOut': 200,
'overlayShow': false,
afterLoad: function () {
$timeout(function(){
$compile($("#content-popup"))($scope);
$scope.$apply();
$.fancybox.resize();
})
this.title = $(this.element).next('.content-popup-footer').html();
},
helpers: {
title: {
type: 'inside'
}
},
});
}
}
});
I'm trying to invoke a function that is inside the controller that invoked the fancybox. This is the html that i'm sending to the fancybox
<a href="{{content.source}}" fancybox="fancybox" id="content-popup"
class="transparent-box content-popup content-picture-container"
rel="campaign-picture-popup" "><a/>
<!--Fancybox footer data begin-->
<div class="content-popup-footer" style="display:none">
<div class="row">
<div class="col-md-6 col-sm-6">
<div class="content-popup-user-info">
<img class="content_picture_profile_pic"
ng-src="{{content.photographer.instagramProfilePicture}}"/>
<div class="content_popup_user_name">
{{content.photographer.instagramUserName}}
</div>
<i class="fa fa-circle small-dot"></i>
<span id="instagram-picture-time-taken">{{content.timeTaken}}</span>
</div>
</div>
<div class="col-md-6 col-sm-6 content_popup_link_container">
<div class="content_popup_link">
<i class="fa fa-link"></i>
View source
</div>
</div>
</div>
<div class="row" id="content-popup-picture-info-row">
<div class="col-md-12">
<p>{{content.description}}</p>
</div>
<div class="col-md-12" id="content-popup-statistics">
<span><i class="fa fa-thumbs-o-up"></i>{{content.likesCount}}</span>
<span><i class="fa fa-comment-o"></i>{{content.commentsCount}}</span>
</div>
</div>
<form role="form">
<div class="form-body">
<div class="form-group">
<div class="input-icon">
<i class="fa fa-pencil-square-o"></i>
<input id="name" type="text" class="form-control"
placeholder="Add caption">
</div>
</div>
</div>
</form>
<div>
<button class="btn select-content-btn"
ng-click="onSelectedContent(content)"
ng-style="content.selected && {'background-color':'#2ecc71'} || !content.selected && {'background-color':'#95a5a6'}">
<i class="fa fa-check" ng-if="content.selected"></i>
<span ng-if="!content.selected">Select</span>
<span ng-if="content.selected">Selected</span>
</button>
</div>
</div>
</div>
<!--Fancybox footer data end-->
The problem that the scope doesn't being recognized inside the fancybox window and i can't invoke the onSelectedContent().
How can i add the scope to the fancybox window so i could activate all the scope's functions and props?
Here is my front-end code:
<div class="wrapper wrapper-content animated fadeIn text-center" ng-controller="ProjectCtrl">
<div class="row row-centered">
<div ng-repeat="project in _projects">
<div class="project-container col-lg-3 col-md-4 col-sm-6 col-centered text-center">
<div class="project-thumb-container">
<div class="project-thumb" style="background-image: url('img/project{{project.projectid}}.jpg');">
<div class="inner-arrow" ui-sref="portal.dashboard({ projectid: {{project.projectid}} })">
<span class="icon-arrow-right fa-5x"></span>
</div>
<div class="project-settings like-link">
<span class="fa fa-gear fa-2x" ng-click="open('test')"></span>
</div>
<div class="project-share like-link">
<span class="fa fa-users fa-2x" ng-click="open('test')"></span>
</div>
</div>
</div>
<h2>{{project.title}}</h2>
</div>
</div>
<div class="project-container col-lg-3 col-md-4 col-sm-6 col-centered text-center">
<div class="project-thumb-container">
<div class="project-thumb thumb-new">
<div class="plus-icon-container">
<span class="fa fa-plus fa-5x"></span>
</div>
</div>
</div>
<h4><i>Add Project</i></h4>
</div>
</div>
</div>
And here is my controller:
'use strict';
angular.module('controllers', ['Projects']).controller('ProjectCtrl', function($scope, Projects) {
var _self = this;
_self.error = null;
_self.processing = true;
Projects.getProjectList().then(function(data){
$scope._projects = data;
}).catch(function(err) {
_self.error = true;
_self.processing = false;
});
});
Here is my route:
.state('root.projects', {
url: "/projects",
controller: "ProjectCtrl as ProjectCtrl",
templateUrl: "views/projects.html",
})
When that code is ran on the front-end, I keep getting this error: Error: [ng:areq] Argument 'ProjectCtrl' is not a function, got undefined