我想使用angular的ng模型來存儲它的值,並使用ng-click將值傳遞給控制器。用我目前的代碼,我總是收到未定義的值。我做錯了什麼?AngularJS - 無法從ng模型中獲取值到控制器
HTML
<ion-content>
<div class="list">
<label class="item item-input">
<textarea ng-model="feed.status"></textarea>
</label>
</div>
</ion-content>
<div class="tabs tabs-icon-left">
<a class="tab-item" ng-click="post(feed)">
<i class="icon ion-arrow-right-b"></i>
</a>
</div>
的JavaScript - 控制器
.controller("PostController", function($scope, $http, $localStorage, $location){
$http.get("https://graph.facebook.com/v2.2/me", { params: { access_token: $localStorage.accessToken, fields: "id, location, picture", format: "json" }}).then(function(result) {
$scope.profileData = result.data;
console.log(result.data);
}, function(error) {
alert("There is a problem with your profile");
console.log(error);
});
$scope.post = function(data){
console.log(data);
}
});
路線
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/feeds')
$stateProvider
.state('login', {
url: '/',
templateUrl: 'templates/login.html',
controller: 'LoginController'
})
.state('profile', {
url: '/profile',
templateUrl: 'templates/profile.html',
controller: 'ProfileController'
})
.state('feeds', {
url: '/feeds',
templateUrl: 'templates/feeds.html',
controller: 'FeedsController'
})
.state('post', {
url: '/post',
templateUrl: 'templates/post.html',
controller: 'PostController'
})
})
發佈您的控件的完整代碼ller – harishr
@entre,當然。更新 –
你的HTML中聲明瞭'ng-controller'在哪裏? – LionC