[AngularJS] I cannot post data to back end from angular6

2018-10-18 Thread chinelookolo28
Am trying to post data to php backend and display json call  response 
message *success* but am having the following errors


*Error in src/app/car.service.ts(42,5): error type*
*observable is not assignable to type Observable*

Here is *app.component.ts* code

import { Component, OnInit } from '@angular/core';

import { Car } from './car';
import { CarService } from './car.service';
   



@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {


  //cars: Car[];


cars: Car="";



  error = '';
  success = '';

car = new Car('', 0);

  constructor(private carService: CarService) {
  }


  ngOnInit() {
//this.getCars();
  }


public regCar(r) {
  this.resetErrors();
  this.carService.store1(this.car)
.subscribe(
  res => {
alert(res);

if (res === 'success') { // or this.cars['message']
// Inform the user
this.success = 'Created successfully';
}

// Reset the form
r.reset();
  },
  err => this.error = err
);
}

  private resetErrors(){
this.success = '';
this.error   = '';
  }

}


Here is the *Car.services.ts*
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse, HttpParams } from 
'@angular/common/http';

import { Observable, throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';

import { Car } from './car';


@Injectable({
  providedIn: 'root'
})
export class CarService {

baseUrl = 'http://localhost/angular-project1/api';


//cars: ;

//cars: Car[];

constructor(private http: HttpClient) { }

  store1(car: Car): Observable {
return this.http.post(`${this.baseUrl}/store1`, { data: car })
  .pipe(
  catchError(this.handleError));
  }

  private handleError(error: HttpErrorResponse) {
console.log(error);

// return an observable with a user friendly message
return throwError('Error! something went wrong.');
  }
}



here is the* car.ts*




*export class Car {  constructor(model: string,price: number,
id?:   number) {}}store.php*


*// pass parameter here*
*$car = [*
*  'message' => 'success'*
*];*
 
*echo json_encode($car);*
*  }*
*  else*
*  {*
*http_response_code(422);*
*  }*







-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] window infinite scrolling function not working with angularjs

2018-11-11 Thread chinelookolo28
Enter code here...

Enter code here...

How to get window scrolling function to work in Angularjs.

Am migrating from jquery to angularjs. I need to convert this three line of 
codes from jquery to angularjs

 
$(window).scroll(function(){
var position = $(window).scrollTop();
var bottom = $(document).height() - $(window).height();





Here is the working code for jquery which alerts position and bottom values

 


$(document).ready(function(){

$(window).scroll(function(){

var position = $(window).scrollTop();
var bottom = $(document).height() - $(window).height();


alert(position);
alert(bottom);
   if( position == bottom ){


/*
$.ajax({
url: 'fetch_data.php',
type: 'post',
data: {row:20},
success: function(response){

$(".post:last").after(response).show().fadeIn("slow");
}
});
   */
}


});

});







Here is my struggle with angularjs but cannot get it to work. Can someone 
help me
  
  
var fetch = angular.module('myapp', []);


fetch.controller('fetchCtrl', ['$scope', '$http','$window', function 
($scope, $http, $window) {


angular.element($window).bind("scroll", function() {
var position = $(window).scrollTop();
var bottom = $(document).height() - $(window).height();


alert(position);
alert(bottom);


  
if( position == bottom ){
  /*
 $scope.getPosts = function(){

$http({
method: 'post',
url: 'getData.php',
data: {row:20}
}).then(function successCallback(response) {
$scope.posts = response.data;
   


});
 }
*/


}


});
  
}]);




-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Agularjs shows ReferenceError: $ is not defined at Object

2018-11-11 Thread chinelookolo28


Am migrating from jquery to angularjs. so I need to convert this three line 
of codes from jquery to angularjs but 
*Agularjs shows ReferenceError: $ is not defined at Object*

 $(window).scroll(function(){
var position = $(window).scrollTop();
var bottom = $(document).height() - $(window).height();





Here is the working code for *jquery *which alerts position and bottom 
values

 


$(document).ready(function(){

$(window).scroll(function(){

var position = $(window).scrollTop();
var bottom = $(document).height() - $(window).height();


alert(position);
alert(bottom);
   if( position == bottom ){


/*
$.ajax({
url: 'fetch_data.php',
type: 'post',
data: {row:20},
success: function(response){

$(".post:last").after(response).show().fadeIn("slow");
}
});
   */
}


});

});







Here is my struggle with* angularjs *but cannot get it to work. but 
Agularjs shows ReferenceError: $ is not defined at Object
  
  
var fetch = angular.module('myapp', []);


fetch.controller('fetchCtrl', ['$scope', '$http','$window', function 
($scope, $http, $window) {


angular.element($window).bind("scroll", function() {
var position = $(window).scrollTop();
var bottom = $(document).height() - $(window).height();


alert(position);
alert(bottom);


  
if( position == bottom ){
  /*
 $scope.getPosts = function(){

$http({
method: 'post',
url: 'getData.php',
data: {row:20}
}).then(function successCallback(response) {
$scope.posts = response.data;
   


});
 }
*/


}


});
  
}]);




-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Angularjs Shows only one Message box instead of many based on users selected.

2019-02-25 Thread chinelookolo28
Angularjs Shows only one Message box instead of many based on users 
selected.

Am trying to build a multi-messaging chatbox using angularjs. Within the 
Angularjs array, I have four users.

Here is my issue:

The application shows only just one popup box irrespective of the user 
clicked.


*Here is what am trying to achieve:*

 what I want is something like facebook multi-chat message box. That is if 
I select multiple user,
Eg. Two users, am supposed to be seeing two popup messagebox that 
corresponds to those users, if select three users
am supposed to being seeing three users popup box and so on...


*Here is the code so far*



 


https://ajax.googleapis.com/ajax/libs/angularjs/1.7.6/angular.min.js";
>


 var app = angular.module('myapp', []);

app.controller('MainCtrl', function($scope) {

  $scope.arr= [
{name:"user1"},
{name:"user2"},
{name:"user3"},
{name:"user4"}
];

//pop div
 $scope.popIt = function(id){
  $scope.popId = ($scope.popId==id)?-1:id;
}

//hide/unhide div partly working
 $scope.IsVisible = false;
$scope.ShowHide = function(id){
$scope.IsVisible = ($scope.IsVisible = true)?-1:id;
}


});






.sidebar {
 width: 250px;
 position: fixed;
 height: 100%;
 right: 0px;
 top: 0px;
 padding-top: 200px;
 padding-bottom: 10px;
 border: 1px solid #b2b2b2;
text-align:bottom;
}



.contact_box{
position:fixed;
bottom:-5px;
width:250px;
  // height:100px;
background:black;
color:white;
border-radius:5px 5px 0px 0px;
  bottom: 0px;
 right: 270px;
display: inline-block;
}








  


 {{ret.name}}






Close
hide/unhide





  Username: {{ret.name}}
Message .
Message .
Message .
Message .
Message .
Message .






  












-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.