Showing posts with label angular js. Show all posts
Showing posts with label angular js. Show all posts

Thursday, 23 June 2016

Unknown provider: $stateProvider

[$injector:unpr] Unknown provider: $stateProvider <- $state <- LoginCtrl

problem :
missing angular-ui-router.js

<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>


steps :
1.
go the project folder and from commandline.

cmd :  bower install angular-ui-router

ref : git

the above command will download package

2. start grunt server

cmd : grunt serve

Wednesday, 22 June 2016

start writing a project in yoman for angular js project

start writing a project in yeoman for angular js project

IN the app folder.

project structure is


1. images.
2. script
2.1 controller folder (all the controller are stored here.)
2.2 app.js (for routing the pages.)
3.style.
4. views. (all the static html stored here.)

create a module address.

1. Create a listItem in index.html in the navigation bar.
ex : <li><a ng-href="#/address">Address</a></li>

2. create a route in app.js

ex :

.when('/address', {
 templateUrl : 'views/address.html',
 controller : 'AdressCtrl',
 controllerAs : 'contact'
 })
3. create address.js in script/controller folder and write adress controller.
ex :
angular.module('scjavaApp')
.controller('AdressCtrl',function(){
console.log("Hhi this from controller");

});

4. In view folder create address.html
<div>
HI this from address page.
</div>

start grunt server and check

Wednesday, 4 May 2016

error: [ng:areq] Argument ' ' is not a function, got undefined

error: [ng:areq] Argument ' ' is not a function, got undefined.

initialize the controller.

solution :

console.log("hi");
 
  var voiceApp =  angular.module("voice",[]);
 
  surveyApp.controller('voiceCTRL', function() {
 
  console.log("hi");
  });

Friday, 29 April 2016

angularjs project scaffolding using yeoman

create a project using yo
prerequisite
a) install npm on your box.

1) install yeoman online using npm command.
cmd : npm install -g yo
ref : github (https://github.com/yeoman/yo)
2) create the project scaffolding using yo command.
note : create a project folder "voiceapp" and move to the directory.
cmd : yo  or (yo angular)
3) We get set of options, choose option based on requirement. here we choose angular.
There are some experimental feature like gulp/saas, based on requirement choose yes or no.
a) angular
b) webapp
..
4) include bootstrap choose yes option.
>( ) angular-animate.js
 ( ) angular-aria.js
 ( ) angular-cookies.js
 (*) angular-resource.js
 ( ) angular-messages.js
 (*) angular-route.js
 (*) angular-sanitize.js
 ( ) angular-touch.js

choose the following angular(resource/route/sanitize).

5) skip if there any option when installation.

angular.js:13550 Error: [ng:areq] Argument 'MynameCtrl' is not a function, got undefined

angular.js:13550 Error: [ng:areq] Argument 'MynameCtrl' is not a function, got undefined

solution :

include controller.js in index file or the required reference file where you are calling

Thursday, 28 April 2016

Genrating project scaffolding for angular js using Yeoman.

step 1.
a) install nodejs window/linux machine or based on the os you have.
ref : nodejs
step 2.
a) install Yeoman ,grunt,bower.
ref : Yeoman
cmd :  install yo.
b) From the given choose angular js and click next.

note :
a) Yeoman : for generating project scaffolding.
b) bower : package manager.
c) grunt : to perform repetitive task, minification,unit testing.



Tuesday, 5 April 2016

Tuesday, 29 March 2016

File upload with  data  using angular js and jersey webservice

1. jersey service.

        @POST
@Path("/public")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void get(
                               @FormDataParam("file") byte[] fileInputStream,
            @FormDataParam("file") FormDataContentDisposition fileInputDetails,
            @FormDataParam("id")String userid){

System.out.println("THis is the ID "+userid);
System.out.println("File Details : "+ fileInputDetails.getFileName());

System.out.println("Reading the String data "+ fileInputStream.toString());

String s = new String(fileInputStream);
   System.out.println("Text Decryted : " + s);

}

2.  create the angular js service,directive,controller

Service.

service('myFileService',["$http",function($http){
console.log("service is called");

this.post = function(uploadUrl, data){

var fd = new FormData();   // bunch of  key,value

console.log("uploaded URL "+uploadUrl);
console.log("uploaded data "+data);

for(var key in data) {

console.log("key is : "+ key + " , value :  "+ data[key]);
fd.append(key, data[key]);
}

$http.post(uploadUrl, fd, {
transformRequest: angular.indentity,
headers: { 'Content-Type': undefined }
})
.success(function(){
console.log("from service success");
})
.error(function(){
console.log("from service failure");
})

}


}]);

Directive : to bind the file data

directive('fileModel', ['$parse', function($parse){
return {
restrict: 'A',
link : function(scope, element, attrs){

var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function(changeEvent){
scope.$apply(function(){
                         modelSetter(scope, changeEvent.target.files[0]);
                });

});
}

};
}]);

Controller :

controller("postCTRL",['$scope','myFileService',function($scope,myFileService){
$scope.sample = {};
$scope.Submit = function(){
console.log($scope.sample.name);
var uploadedURL = "/public";
var data = $scope.sample;
myFileService.post(uploadedURL,data);
 
}
 }]);

3. HTML FORM

<form>


<p> Name : <input type="text" name="name" ng-model="sample.id" required /></p>
   
<input type="file" id="exampleInputFile" file-model="sample.file">  
   
<button ng-click="Submit()">Submit</button>

</form>
{{sample}}

</div>



Ref :
1. stackoverflow