私はAngularJSを初めて使っていて、コードを試していました。私が得られないことは、別々のモジュールを作る方法です。たとえば、ログイン、登録、パスワードを忘れたなどのすべてのユーザー機能用のモジュールを用意したいとします。Separate controllers AngularJS
これを行う方法については、適切なチュートリアルが見つかりません。誰か助けてくれますか?
<body ng-app="starter" ng-controller="AppCtrl">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content padding="true">
<form ng-submit="submit()">
<label class="item item-input item-stacked-label">
<span class="input-label">Username</span>
<input type="text" name="username" placeholder="enter username" ng-model="data.username">
</label>
<input class="button button-block button-positive" type="submit" name="submit" value="Submit to server">
</form>
<div class="card">
<div class="item item-text-wrap">
Response: <b ng-bind="response"></b>
</div>
</div>
</ion-content>
</ion-pane>
</body>
編集(私はそれがあるべきだと思う何):
私 HTMLで// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.controller('AppCtrl', function($scope, $http) {
$scope.data = {};
$scope.submit = function(){
var link = 'http://nikola-breznjak.com/_testings/ionicPHP/api.php';
$http.post(link, {username : $scope.data.username}).then(function (res){
$scope.response = res.data;
});
};
});
そして、この:
私は私のapp.jsでこれを持っています
My app.js:
angular.module('starter', ['ionic','login'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
マイusersController.js:
var app = angular.module("login", []);
app.controller('AppCtrl', function($scope, $http) {
$scope.data = {};
$scope.submit = function(){
var link = 'http://nikola-breznjak.com/_testings/ionicPHP/api.php';
$http.post(link, {username : $scope.data.username}).then(function (res){
$scope.response = res.data;
});
};
});
私はuserController.js私のhtmlでが含まれます。
https://github.com/johnpapa/あなたは、この非常によく書かれたブログを読むことができます詳細については
angle-styleguide/blob/master/a1/README.md#modules –
これが役立つなら、私の答えをチェックしてください! –