0

So I am using this example https://jsfiddle.net/jccrosby/eRGT8/ to created tabbed spa. So far this is working but when i try to add separate controller combining http://jsfiddle.net/mjaric/pj5br/ like below, i am losing even the original tabs.

<div ng-app="TabsApp">
<div id="tabs" ng-controller="TabsCtrl">
    <ul>
        <li ng-repeat="tab in tabs" 
            ng-class="{active:isActiveTab(tab.url)}" 
            ng-click="onClickTab(tab)">{{tab.title}}</li>
    </ul>
    <div id="mainView">
        <div ng-include="currentTab"></div>
    </div>
</div>
<script type="text/ng-template" id="one.tpl.html">
    <div id="viewOne" >
        <h1>View One</h1>
        <p>1.</p>
    </div>
</script>

<script type="text/ng-template" id="two.tpl.html">
    <div id="viewTwo" ng-controller="PeopleCtrl">
        <h1>View Two</h1>
            <p>Click <a ng-click="loadPeople()">here</a> to load</p>
  <table>
  <tr>
      <th>Id</th>
      <th>First Name</th>
      <th>Last Name</th>
  </tr>
  <tr ng-repeat="person in people">
      <td>{{person.id}}</td>
      <td>{{person.firstName}}</td>
      <td>{{person.lastName}}</td>
  </tr>
  </table>
    </div>
</script>

<script type="text/ng-template" id="three.tpl.html">
    <div id="viewThree">
        <h1>View Three</h1>
        <p>3.</p>
    </div>
</script>

js file

var mockDataForThisTest = "json=" + encodeURI(JSON.stringify([
{
id: 1,
firstName: "Peter",
lastName: "Jhons"},
{
id: 2,
firstName: "David",
lastName: "Bowie"}
]));

var app = angular.module('TabsApp', []);
app.controller('TabsCtrl', ['$scope', function ($scope) {
$scope.tabs = [{
        title: 'One',
        url: 'one.tpl.html'
    }, {
        title: 'Two',
        url: 'two.tpl.html'
    }, {
        title: 'Three',
        url: 'three.tpl.html'
}];

$scope.currentTab = 'one.tpl.html';

$scope.onClickTab = function (tab) {
    $scope.currentTab = tab.url;
}

$scope.isActiveTab = function(tabUrl) {
    return tabUrl == $scope.currentTab;
}
}]);
app.controller('PeopleCtrl',['$scope','$http',function ($scope, $http) {

$scope.people = [];

$scope.loadPeople = function() {
    var httpRequest = $http({
        method: 'POST',
        url: '/echo/json/',
        data: mockDataForThisTest

    }).success(function(data, status) {
        $scope.people = data;
    });

};

}]};

output like: below showing just 1 tab and nothing else

{{tab.title}}

So i need the 2nd example working inside the 2nd tab. new to Angular js so trying out. I am not sure what I am doing wrong. Here is the sample:

https://jsfiddle.net/gen14rp5/

1 Answer 1

1

angular js library is not added just add the library reference to the fiddle

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

3 Comments

sorry missed it but the issue is not related to it. I am running it locally
yes, fixes the issue but this has the values directly assigned? anyway to use the httpRequest as given in the example 2
here i did some changes check it out :) plnkr.co/edit/8MOquxlcrVsU0Cm2SVxY?p=preview

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.