2

i have written a simple controller to filter an array but this is giving error. By removing "data-ng-controller" or without controller its working fine. i am not getting where is the error.Please find the code in the url-

function SimpleController($scope){
        $scope.names=[
            {name:'abc',address:'xyz'},
            {name:'abcxyz',address:'xxyyzz'},
            {name:'abcmno',address:'mnoap'},
            {name:'aabbcc',address:'ppqqrrr'}
            ];
    }

http://jsfiddle.net/somsekhardash/vL0hzod9/

2 Answers 2

3

You've defined the Controller in the onLoad function so when the markup is rendered and parsed by angular the controller function doesn't exist. If you move it in to the body (or a separate script file ideally) it should work.

See the updated fiddle, with the noWrap option: http://jsfiddle.net/vL0hzod9/2/

Sign up to request clarification or add additional context in comments.

Comments

2

There is no problem with the code..

You created a jsfiddle and were running the controller function when the page loads, see there at thee left hand side upper corner of jsfiddle, you can select, below the framework, `nowrap in body.

Working fiddle`http://jsfiddle.net/vL0hzod9/1/

function SimpleController($scope){
            $scope.names=[
                {name:'abc',address:'xyz'},
                {name:'abcxyz',address:'xxyyzz'},
                {name:'abcmno',address:'mnoap'},
                {name:'aabbcc',address:'ppqqrrr'}
                ];
        }

Doesnt need to change code. Just the difference is I wrap the controller logic in body, which you had wrapped onload previously..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.