0
<div ng-init="items=[{'id':1,'name':'Amit'}]">
    <input type="text" size="40" ng-model="searchString" placeholder="Search">
    <ul>
        <li ng-repeat="i in items | filter:searchString">{{ i.id }}</li>
    </ul>
</div>

Output :

<div ng-init="items=[{'id':1,'name':'Amit'}]">
    <input type="text" size="40" ng-model="searchString" placeholder="Search" class="ng-pristine ng-untouched ng-valid ng-empty">
    <ul>
        <!-- ngRepeat: i in items | filter:searchString -->
    </ul>
</div>

When I use single key value then it's not working.But when I use multiple key value like: [{'id':1,'name':'Amit'},{'id':2,'name':'Neeraj'}] then it's working. What is the mistake in my code.

Amit
  • 129
  • 1
  • 9
  • 4
    it seems to work for me http://jsfiddle.net/Lvc0u55v/5595/ – gaurav5430 Jun 19 '16 at 09:33
  • 2
    I voted to close this question due to the problem not being reproducible. Also, this isn't an appropriate use for `ng-init`; `ng-init` is intended for specialized usage where it is impossible to initialize the data in any other way, like in a controller for example. – Claies Jun 19 '16 at 09:52
  • @Claies I can't get data to app.js file.Controller can work when I use this in same page not in another js file.I'm using django framework that's symbol {{ }} is also same as angularJs – Amit Jun 19 '16 at 10:26
  • you can change the interpolation symbols for angular. https://docs.angularjs.org/api/ng/provider/$interpolateProvider#!/. However, I'm not sure how that has anything to do with `ng-init`, and saying you can't use data in another js file doesn't make sense without more explanation. – Claies Jun 19 '16 at 10:29
  • @Claies this http://stackoverflow.com/questions/18331811/defining-django-context-variable-in-jquery-giving-me-error url will help for understanding we can't use django data in anotherjs file.If we want to use in js file you have to make a method in js and called from main page. – Amit Jun 19 '16 at 20:47
  • I think perhaps you are confused about what that post is suggesting. You *definitely* can use multiple js files in django. That being said, it's not even clear what that has to do with this not being an appropriate use for nginit – Claies Jun 19 '16 at 21:06

2 Answers2

0

As you have single key, you can directly access it using items. Id, and items.name

When you have multiple value, you can use ng-repeat for a loop. Hope this might help you.

shrike
  • 4,449
  • 2
  • 22
  • 38
Himesh Suthar
  • 562
  • 4
  • 14
0

i double check this and its working

    <html>

<body ng-app="">

    <div ng-init="items=[{'id':1,'name':'Amit'}]">
        <input type="text" size="40" ng-model="searchString" placeholder="Search">
        <ul>
            <li ng-repeat="i in items | filter:searchString">{{ i.id }}</li>
        </ul>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
</body>

</html>
abdoutelb
  • 1,015
  • 1
  • 15
  • 33