Showing posts with label Angularjs. Show all posts
Showing posts with label Angularjs. Show all posts

Friday, 14 November 2014

Order by filter in js controller

Below code will sort the list listLeaves in the descending order of date field .

$scope.listLeaves = $filter('orderBy')($scope.listLeaves, "-date")

Friday, 1 August 2014

AngularJs: order by filter

Use order by like this:

<tr ng-repeat="emp in empList | orderBy:joiningDate">
</tr>

Above code will show you emp list in ascending order of joining date.

<tr ng-repeat="emp in empList | orderBy:-joiningDate">
</tr>

You can see I used - (hyphen) in above code. Due to this hyphen employee list will show in descending order of joining date.

Monday, 28 July 2014

Angularjs filtered array length

In this example, I am applying a filter on list and after that I am getting the length.

<tr ng-show="showdate && (yourlist | filter:searchEmp).length > 0"><td class='appointment_header' style="font-weight:bold;" colspan="3"><span> {{----}}</span></td></tr>

Tuesday, 22 July 2014

Solved:: Phonegap access origin problem with angularjs

I am giving simple steps to solve Phonegap access origin problem with angularjs

You have to create a filter at your java server side to allow cross domain requests (If your angularjs requests resources from any other java server):


A. Your java filter class will be look like as:
package com.abc.security.corsfilter.util;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CORSFilter implements Filter {
    public void destroy() {
    }

    public static String VALID_METHODS = "DELETE, HEAD, GET, OPTIONS, POST, PUT";

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException,
            IOException {
        HttpServletRequest httpReq = (HttpServletRequest) req;
        HttpServletResponse httpResp = (HttpServletResponse) resp;

        // No Origin header present means this is not a cross-domain request
        String origin = httpReq.getHeader("Origin");
        if (origin == null) {
            // Return standard response if OPTIONS request w/o Origin header
            if ("OPTIONS".equalsIgnoreCase(httpReq.getMethod())) {
                httpResp.setHeader("Allow", VALID_METHODS);
                httpResp.setStatus(200);
                return;
            }
        } else {
            // This is a cross-domain request, add headers allowing access
            httpResp.setHeader("Access-Control-Allow-Origin", origin);
            httpResp.setHeader("Access-Control-Allow-Methods", VALID_METHODS);

            String headers = httpReq.getHeader("Access-Control-Request-Headers");
            if (headers != null)
                httpResp.setHeader("Access-Control-Allow-Headers", headers);

            // Allow caching cross-domain permission
            httpResp.setHeader("Access-Control-Max-Age", "3600");
        }
        // Pass request down the chain, except for OPTIONS
        if (!"OPTIONS".equalsIgnoreCase(httpReq.getMethod())) {
            chain.doFilter(req, resp);
        }
    }

    public void init(FilterConfig config) throws ServletException {

    }

}

B. Make entry of this filter in web.xml. Remember entry of this filter should be first, if you have any other filters entry in your web.xml

      <filter>
         <filter-name>CorsFilter</filter-name>
         <filter-class>com.certain.security.corsfilter.util.CORSFilter</filter-class>
     </filter>
     <filter-mapping>
         <filter-name>CorsFilter</filter-name>
         <url-pattern>/*</url-pattern>

     </filter-mapping>


*******Now we are going to make changes in code of your phonegap application.******


Your phonegap activity class should look like this:

package com.example.hello;

import android.os.Bundle;
import org.apache.cordova.*;
import android.webkit.CookieManager;

public class HelloWorld extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
CookieManager.setAcceptFileSchemeCookies(true); // this must be in this class
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///index.html");
    }
}

Changes in /usr/local/src/node-v0.10.29/hello/config.xml

use <access origin="*" />