javascript - Angularjs routing using $state gotten raw html tags -
i used below code , gotten raw html result. i'm seeing expression of {{welcome}} etc. guess i'd done wrong somewhere , caused failed render. didn't see error in console of chrome.
my app.js
app.config(function($stateprovider, $urlrouterprovider) { $stateprovider .state('threadlisting', { url: '/', templateurl: 'threadlisting.html', controller: 'appctrl' }) .state('threaddetail.php', { url: '/threaddetail', templateurl: 'threaddetail.html', controller: 'appctrl' }) $urlrouterprovider.otherwise("/"); })
my html this
<ion-content> <script id="threadlisting.html" type="text/ng-template"> <ion-view> <h1>welcome {{name}}</h1> </ion-view> </script> <script id="threaddetail.html" type="text/ng-template"> <ion-view> <h2>{{age}}</h2> </ion-view> </script> </ion-content>
in code, see there's no controller declaration.
you must define controller, in order enable angular resolve placeholders.
try :
<script type="text/javascript"> var myapp = angular.module("myapp", []); myapp.controller("indexcontroller", function($scope) { $scope.name = "test"; $scope.age = 123; }); </script> <script id="threadlisting.html" type="text/ng-template"> <ion-view ng-controller="indexcontroller"> <h1>welcome {{name}}</h1> </ion-view> </script> <script id="threaddetail.html" type="text/ng-template"> <ion-view ng-controller="indexcontroller"> <h2>{{age}}</h2> </ion-view> </script>
Comments
Post a Comment