Ng-click不会执行

时间:2017-06-19 10:40:30

标签: javascript angularjs ionic-framework angular-controller

我想让我的div标签可点击,但我无法让它工作。 我正在使用Angular 1.5和Ionic V1。

当用户登录时,我希望他/她能够看到此视图:

<ion-modal-view>
<ion-header-bar>
    <div class="buttons">
        <button class="button" ng-click="closeModal()"><i class="ion-chevron-left big-icon"></i></button>
    </div>
</ion-header-bar>
<ion-content>
    <div class="modal" style="background-color: #EDEEF1;" ng-controller="LoginCtrl">
        <div class="row row-white">
            <div class="col col-grey">
                <div class="divider20"></div>
            <h4 style="margin-top:30px;">Martin Nordström</h4>
            </div>
        </div>
        <div class="row row-white">
            <div class="col col-grey">
                <p style="color: #006E78; margin-bottom:40px;">990624****</p>
            </div>
        </div>
        <div class="divider20"></div>
        <div class="row row-white main-container">
            <div class="col col-grey">
                <p style="color:#006E78;">Vart vill du ta emot dina leveranser?</p>
            </div>
        </div>

        <div class="info-box" ng-class="{'info-box-active':isActive}" ng-click="activeBtn()" ng-controller="LoginCtrl">
            <div class="box-row">
                <div class="header">
                    <p class="leftText">IKANO Bostad</p>
                    <p class="rightText">Leveransrum</p>
                </div>
            </div>

            <div class="box-row">
                <div class="fields">
                    <p class="leftText">Folkungagatan 100</p>
                    <p class="rightText">10 kr/månad</p>
                </div>
            </div>
        </div>

        <div class="info-box">
            <div class="box-row">
                <div class="fields mixed">
                    <p class="leftText">Lägg till en ny leveransbox</p>
                    <p class="rightText">0 kr/månad</p>
                </div>
            </div>
        </div>

        <div class="row row-white">
            <div class="col col-grey">
                <button style="border-radius:50px; width:200px; height:45px;" class="button" ng-click="closeModal()">Klar</button>
            </div>
        </div>
        <div class="divider20"></div>
    </div>
</ion-content>

该视图在用户登录后显示,但所有ng-click都无效。这是控制器:

.controller('LoginCtrl', function ($scope, alerter, $localStorage, WizardHandler, datamapper, data, api, $state, authToken, $ionicModal, storage, endpointHandler, loadingHandler, $ionicPopup, $timeout) {

在控制器内我有这个功能:

$timeout(function () {
$ionicModal.fromTemplateUrl('templates/deliveryDestination.modal.html', {
    scope: $scope.$scope,
    animation: 'slide-in-up'
}).then(function (modal) {
    $scope.modal = modal
    modal.show()
})

},1000)

编辑:这是activeBtn()

的实施
$scope.isActive = false
$scope.activeBtn = function () {
    console.log("clicked!");
    $scope.isActive = !$scope.isActive
}

我是Angular的新手,但凭借我的(小)经验,我认为问题与未正确连接的控制器有关。但我错了!希望我们能够一起解决这个问题,我很感激能得到的所有支持。

由于

3 个答案:

答案 0 :(得分:1)

您需要将 ng-controller="LoginCtrl" 放在所有div之外,否则$ scope不会获得上下文。

 <ion-modal-view ng-controller="LoginCtrl">

答案 1 :(得分:1)

myDoc.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter
Object currentPage = Word.WdFieldType.wdFieldPage;
myDoc.ActiveWindow.Selection.Fields.Add(myDoc.ActiveWindow.Selection.Range, ref currentPage)
if (MessageVal.contains("encrypt")) {
                byte[] encrypted =result.getCryptoObject().getCipher().doFinal(message.getBytes());
                String newmessage = Base64.encodeToString(encrypted, Base64.URL_SAFE);
                SharedPreferences sharedPreferences = PreferenceManager
                       .getDefaultSharedPreferences(context);
               SharedPreferences.Editor editor = sharedPreferences.edit();
               editor.putString("messageValue", newmessage);
              editor.apply();
              Intent intent = new Intent(context, sampleAcitvity.class);
               context.startActivity(intent);


           } else if (MessageVal.contains("decrypt")) {

               SharedPreferences sharedPreferences = PreferenceManager
                       .getDefaultSharedPreferences(context);
              String MessageFrm = sharedPreferences.getString("messageValue", null);

               Toast.makeText(context, "b4value"+MessageFrm, Toast.LENGTH_LONG).show();
              byte[] dataval=  Base64.decode(MessageFrm, Base64.URL_SAFE);
                byte[] data = result.getCryptoObject().getCipher().doFinal(dataval);
               String stringDecryptyedval = new String(data, "UTF-8");

               Toast.makeText(context, "sucessfully decrpted"+stringDecryptyedval, Toast.LENGTH_LONG).show();

               Intent intent = new Intent(context, sampleAcitvity.class);
               context.startActivity(intent);
           }

我没有看到这方面的问题,你可以查看并与你的

进行比较

答案 2 :(得分:0)

&#13;
&#13;
angular.module('myApp', [])
  .controller('LoginCtrl', function($scope) {
    $scope.activeBtn = function(){
	
	alert("asdasd")
	}
  });
&#13;
<html ng-app="myApp">

<head>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.18/angular.js"></script>
  <script type="text/javascript" src="app.js"></script>
  
  <title>Angular-Google-Charts Example</title>
</head>

<body>
  <div class="modal" style="background-color: #EDEEF1;" ng-controller="LoginCtrl">
        <div class="row row-white">
            <div class="col col-grey">
                <div class="divider20"></div>
            <h4 style="margin-top:30px;">Martin Nordström</h4>
            </div>
        </div>
        <div class="row row-white">
            <div class="col col-grey">
                <p style="color: #006E78; margin-bottom:40px;">990624****</p>
            </div>
        </div>
        <div class="divider20"></div>
        <div class="row row-white main-container">
            <div class="col col-grey">
                <p style="color:#006E78;">Vart vill du ta emot dina leveranser?</p>
            </div>
        </div>

        <div class="info-box" style="background-color:red;" ng-click="activeBtn()">
            <div class="box-row">
                <div class="header">
                    <p class="leftText">IKANO Bostad</p>
                    <p class="rightText">Leveransrum</p>
                </div>
            </div>

            <div class="box-row">
                <div class="fields">
                    <p class="leftText">Folkungagatan 100</p>
                    <p class="rightText">10 kr/månad</p>
                </div>
            </div>
        </div>

        <div class="info-box">
            <div class="box-row">
                <div class="fields mixed">
                    <p class="leftText">Lägg till en ny leveransbox</p>
                    <p class="rightText">0 kr/månad</p>
                </div>
            </div>
        </div>

        <div class="row row-white">
            <div class="col col-grey">
                <button style="border-radius:50px; width:200px; height:45px;" class="button" ng-click="closeModal()">Klar</button>
            </div>
        </div>
        <div class="divider20"></div>
    </div>
</body>

</html>
&#13;
&#13;
&#13;

工作得很好。刚刚移除ng-controller="LoginCtrl"

旁边的ng-click="activeBtn"