控制器未注册angular js spa

时间:2018-06-09 18:59:12

标签: javascript angularjs

我的水疗中心显示以下错误...我几乎没有尝试,但我没有得到解决方案......我是新的角度......任何帮助都表示赞赏......

  

Err :: [$ controller:ctrlreg]名为'Mcontroller'的控制器   没有注册。

的index.html

 guard emailAddress.text != "" , password.text != "" , fullName.text != ""
        else {
            errorOutlet.isHidden = false
            errorOutlet.text = "one or more fields are empty."
            UIApplication.shared.endIgnoringInteractionEvents()
            return SVProgressHUD.dismiss()
        }

    if password.text != "" , emailAddress.text != "" , fullName.text != "" {
   Auth.auth().createUser(withEmail: emailAddress.text! , password: password.text!, completion: { (user, error) in

    if let error = error {
        print(error.localizedDescription)
        SVProgressHUD.dismiss()
        UIApplication.shared.endIgnoringInteractionEvents()

        if let errCode = AuthErrorCode(rawValue: error._code) {
            switch errCode {

            case .emailAlreadyInUse:
                self.errorOutlet.isHidden = false
                self.errorOutlet.text = "The email you entered is already in use"

            case .invalidEmail:
                self.errorOutlet.isHidden = false
                self.errorOutlet.text = "The Email you entered is invalid"

            case .internalError:
                self.errorOutlet.isHidden = false
                self.errorOutlet.text = "An internal error occured! Try again."

            case .networkError:
                self.errorOutlet.isHidden = false
                self.errorOutlet.text = "Check your internet connection."

            case .weakPassword :
                self.errorOutlet.isHidden = false
                self.errorOutlet.text = "Your password should contain more than 7 characters"

            default : break

            }
        }
    }



    // the auth returns a user
    if let user = user {

        let changeRequest = Auth.auth().currentUser!.createProfileChangeRequest()
        changeRequest.displayName = self.fullName.text!
        changeRequest.commitChanges(completion: nil)

        let imageRef = self.userStorage.child("\(user.uid).jpg")
        let data = UIImageJPEGRepresentation(self.profileImage.image!, 0.5)
        let uploadTask = imageRef.putData(data! , metadata: nil, completion: { (metadata, err) in
            if err != nil {
                print(err!.localizedDescription)

                //error


                Auth.auth().currentUser?.delete(completion: nil)
                self.errorOutlet.isHidden = false
                self.errorOutlet.text = "An error occured. Try again!"
                UIApplication.shared.endIgnoringInteractionEvents()
                SVProgressHUD.dismiss()

            }


            imageRef.downloadURL(completion: { (url , er) in
                // in case of error
                if er != nil{
                    print(er!.localizedDescription)
                    SVProgressHUD.dismiss()
                    Auth.auth().currentUser?.delete(completion: nil)
                    self.errorOutlet.isHidden = false
                    self.errorOutlet.text = "An error occured. Try again!"
                    UIApplication.shared.endIgnoringInteractionEvents()
                }

contrller.js

<!DOCTYPE html>

<html ng-app="Dapp">
<head>
<meta charset="ISO-8859-1">
<script type="text/javascript" src="JS/angular.js"></script>
<script type="text/javascript" src="JS/angular-route.js"></script>
<title>DAPP</title>
</head>
<body ng-controller="Mcontroller">
<div class="ng-view"></div>

<script type="text/javascript" src="controllers/Mcontroller.js"></script>
<script type="text/javascript" src="controllers/Controller.js"></script>
<script type="text/javascript" src="controllers/Logincontrol.js"></script>

</body>
</html>

Mcontrol.js

var app=angular.module('Dapp',['ngRoute']);
app.config(function($routeProvider) {

     $routeProvider
      .when('/', {templateUrl : 'Pages/login.html',controller  : 'Mcontroller' })
      .when('/login', {templateUrl : 'Pages/login.html',controller  : 'Logincontrol' })     
});

的login.html

app.controller('Mcontroller',function($scope){

        alert("HELLO");

});

1 个答案:

答案 0 :(得分:1)

尝试将序列更改为:

(以下序列假定angular.module('Dapp',[]);文件中存在Controller.js

<script type="text/javascript" src="controllers/Controller.js"></script>
<script type="text/javascript" src="controllers/Mcontroller.js"></script>
<script type="text/javascript" src="controllers/Logincontrol.js"></script>

确保html页面的angular.module('Dapp',[]); js`文件中<script> as the 1st 包含