AngularJS ng-model $scope in ng-repeat is undefined

后端 未结 4 1917
有刺的猬
有刺的猬 2020-12-04 18:24

I apologize in advance if i\'m not wording this properly. I have a textbox with ng-model inside an ng-repeat and when I try to get the textbox valu

4条回答
  •  無奈伤痛
    2020-12-04 19:04

    Split the model up into heading and value

    angular.module('MyApp',[]);
    
    function PostCtrl($scope) {
         $scope.posts = [{heading:'tech',value:''}, {heading:'news',value:''},     {heading:'sports',value:''},{heading:'health',value:''}];
    
        $scope.savePost = function(post){
            alert( 'post stuff in textbox: ' + post);
        }
    }
    

    HTML below..

    {{post.heading}} save post

    Check out this Fiddle..

提交回复
热议问题