javascript - option selected not working from AngularJS template -
i'm new angularjs, simple, can't seem figure out. problem not in angularjs code itself, i'm sure somehow connected, because i've tried in blank pure-html test page, , worked, how it's supposed to.
headers.html:
<table> <thead> <tr> <td colspan="2" align="right"> sort headers by: <select ng-model="sortheaders"> <option value="rating">rating</option> <option value="id" selected>id</option> </select> </td> </tr> <tr> <th>rating</th> <th>header</th> </tr> </thead> <tbody> <tr ng-repeat="header in headers | filter:search | orderby:sortheaders"> <td>{{header.rating}}</td> <td>{{header.title}}</td> </tr> </tbody>
the problem here is, title says, <option value="id" selected>
not being selected @ page load, how it's supposed be. headers.html is, obviously, template data output. , job perfectly, except selected
problem.
it's loaded headers_app.js:
var headersapp = angular.module('headersapp', []); headersapp.directive('headers', [function () { return { restrict: 'e', controller: function($scope, $http) { $http.get('/api/headers.json').success(function(data) { $scope.headers = data.headers; }); }, templateurl: '/templates/headers.html', replace: true, link: function (scope, element, attrs) { console.log('linked headersapp'); } }; }]);
and, of course, there guy inside index.html:
... <headers> </headers> ...
once again, else works expected. problem supposed-to-be-selected option not selected @ page load.
any ideas?
link: function (scope, element, attrs) { scope.sortheaders = "id"; }
as said in other responses, can way also:
<select ng-model="sortheaders"> <option value="rating">rating</option> <option value="id" ng-selected="true">id</option> </select>
Comments
Post a Comment