Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi friends,

angularjs field validation for Upload file .

-Required field validation
-invalid file format
-max length


i have done this using directive anybody please tell me how to do this using without directive

What I have tried:

<div id="content">
                            <button style="background-color:"red" ng-click="Data()"><span style="color:white">Browse</span></button>
                            <span id="re" ng-show="(Name!='')">{{Name}}</span>
                            <span ng-show="(Name=='')">No file selected</span>
                        </div>
                        <p ng-show="(Message)" style="color:red;margin-left:-50px;">Please Select a File</p>
                        <p ng-show="mageSize" style="color:red;margin-left:-50px;">Please Select the Image Max Size of 1 MB </p>
                        <p ng-show="FormatMessage" style="color:red;margin-left:-90px;">Please Select a Valid File - .jpg </p>
                    </div>
Posted
Comments
Andy Lanng 28-Jun-17 11:45am    
Why do you want to avoid using a directive? That's exactly what they are for.
The "why" might help us find a better solution for you
Member 11183217 30-Jun-17 5:19am    
hi Andy thanks for time to reply, i understood actually what my scenario was i wont create more than one directive per page . so that i didn't create another directive for file validation.myself i thought i could be complete this without that(directive).i am not found or asking better solution here. just asked this will be possible or not.now i am done this one without using directive.
Andy Lanng 30-Jun-17 9:05am    
I think you're doing it wrong :S
In my code, I have no more than 1 controller per page. I have directives for controls I use. I have one for Invoices which are repeatedly rendered, another for my signalr management, and yet another for my file upload. Controllers are specific to a page (or segment) but Directives are specific to a single control which can be reused in many controllers.

If you insist on not using a controller for your file-upload script, then you will have to include it in the page controller and specify the elements with selectors.
Member 11183217 5-Jul-17 11:16am    
thanks andy i got the result.
Member 11183217 5-Jul-17 11:19am    
i explain to them they gave me a permit to add directive. so now i done this with directive inside i have written entire file validation .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900