为什么ng-click在示例中不起作用

时间:2016-10-25 07:21:14

标签: javascript angularjs angularjs-ng-click

我可以看到点击控件不通过chrome调试器转到控制器。我在视图和控制器中有简单的代码。另外,我没有收到任何错误。任何帮助,将不胜感激。

查看

#include <stdio.h>
#include <stdlib.h>

#define MAXC 128

typedef enum { err = -1, Normal = 1, Hard, Insane } DifficultyKind;

typedef struct {
    char name[MAXC];
    int hit_id;
    int dollarvalue;
    DifficultyKind difficulty;
} Target_Data;

DifficultyKind read_difficulty_kind (const char *prompt)
{
    int rtn, temp;

    printf ("%s\n\n"
            " 1: Normal Difficulty\n"
            " 2: Hard Difficulty\n"
            " 3: Insane Difficulty\n\n", prompt);

    while ((rtn = scanf (" %d", &temp)) != 1 || (temp < 1 || temp > 3)) {
        if (rtn == EOF)
            return err;  /* trap cancel of input (ctrl+d, ctrl+z) */
        fprintf (stderr, "error: invalid selection\n"
                        "Please make a selection between 1 and 3:\n\n"
                        " 1: Normal Difficulty\n"
                        " 2: Hard Difficulty\n"
                        " 3: Insane Difficulty\n\n");
    }

    return temp;
}

Target_Data *read_target_data (Target_Data *result, const char *prompt)
{
    int rtn;

    printf ("%s\n\nEnter name: ", prompt);
    while ((rtn = scanf (" %127[^\n]%*c", result->name) != 1))
        if (rtn == EOF) {
            fprintf (stderr, "warning: input canceled, exiting.\n");
            exit (EXIT_FAILURE);
        }

    printf ("Enter hit ID: ");
    while ((rtn = scanf (" %d", &(result->hit_id)) != 1) ||
            result->hit_id < 0) {
        if (rtn == EOF) {
            fprintf (stderr, "warning: input canceled, exiting.\n");
            exit (EXIT_FAILURE);
        }
        fprintf (stderr, "Please enter a value of 0 or higher \n");
        printf ("Enter hit ID: ");
    }

    printf ("Enter $ value of target: ");
    while ((rtn = scanf (" %d", &(result->dollarvalue)) != 1) || 
            result->dollarvalue < 0) {
        if (rtn == EOF) {
            fprintf (stderr, "warning: input canceled, exiting.\n");
            exit (EXIT_FAILURE);
        }
        fprintf (stderr, "Please enter a value of 0 or higher \n");
        printf ("Enter $ value of target: ");
    }

    if ((result->difficulty = read_difficulty_kind ("Please select the"
            " level of difficulty from the options below:")) == err) {
        fprintf (stderr, "warning: input canceled, exiting.\n");
        exit (EXIT_FAILURE);
    }

    return result;
}

void print_target_data (Target_Data *toPrintData)
{
    printf ("\nDifficulty: %d, Target: %s, Hit ID: %i, $%i,\n",
            toPrintData->difficulty, toPrintData->name,
            toPrintData->hit_id, toPrintData->dollarvalue);
}

int main (void) {

    Target_Data Target_Data = { .name = "" };
    read_target_data (&Target_Data, 
                    "Please enter the details of your bounty: ");
    print_target_data (&Target_Data);

    return 0;
}

控制器

$ ./bin/difficultystruct
Please enter the details of your bounty:

Enter name: Some Funny Name
Enter hit ID: 123
Enter $ value of target: 234
Please select the level of difficulty from the options below:

 1: Normal Difficulty
 2: Hard Difficulty
 3: Insane Difficulty

0
error: invalid selection
Please make a selection between 1 and 3:

 1: Normal Difficulty
 2: Hard Difficulty
 3: Insane Difficulty

4
error: invalid selection
Please make a selection between 1 and 3:

 1: Normal Difficulty
 2: Hard Difficulty
 3: Insane Difficulty

2

Difficulty: 2, Target: Some Funny Name, Hit ID: 123, $234,

路由器

<div class="logInBtn">
   <a data-ng-click="submitLoginDetails()">
     <button type="button" class="btn btn-primary">Log In</button>
   </a>
</div>

服务

app.controller('loginPageController',function($scope, $http, assimilationSurveyService){

    $scope.submitLoginDetails = function(){

        $scope.loginData = {
          "password": "pass1234",
          "userId": "userabc"
        };

        assimilationSurveyService.sendLoginData($scope.loginData)
            .success(function(data) {
                alert("Hi!");
            });
    }

});

单击登录按钮时指针不会进入控制器。所以,让我知道为什么在ng-click上我没有让程序进入控制器部分。

  

即使我删除了锚点并设置了ng-click in按钮,我也没有被重定向到控制器代码功能。奇怪的问题!

1 个答案:

答案 0 :(得分:0)

答案很简单:

此视图已加载默认值,因此控制器未绑定到该视图。

解决方案应该是:

.otherwise({title:'Feedback', templateUrl:'loginPage.html',controller:'loginPageController'});

否则我错过了给控制器,因为这是第一个也是默认页面,否则它会采取其他操作,但由于没有控制器,它无法连接到相应的控制器。

感谢大家的帮助......但这真的帮我调试了问题!