单击JS中链接的API调用

时间:2015-12-26 19:20:01

标签: javascript angularjs

我试图在点击链接时调用api并在新视图中显示数据,但我没有看到任何数据既不是控制台上的错误。我也尝试使用Log但这也没有给我任何线索。 这是我在View中的代码:         

     myStore.controller("Home", function ($scope, StoreService, $log, $window) {
 var onComplete = function (data) {
        $scope.gettempdata = data;
    }
    var onError = function (reason) {
        alert(reason.errorcode);
    }
$scope.GetItemDetails = function (Id) {
        $log.info("wait for 5 secs");
        StoreService.getItemDetails(Id).then(onComplete, onError);
        $log.info("done");
    }
});

我正在尝试调用GetItemDetails(Id)。 控制器代码:

var myStore = angular.module('groceries', ['ngRoute'])
.config(function ($routeProvider) {
    $routeProvider.
        when("/Home", {
            templateUrl: "/Index.html",
            controller: "Home"
        }).

        when("/Name", {
            templateUrl: "Store/Product.html",
            controller: "Home"
        }).

    otherwise
    ({
        redirectTo: "/Home"
    })

});

App.js代码:

<html ng-app="groceries">
<head>
<script> ALL scripts</scripts>
 <title></title>
</head>
<body>

    <!-- 
        bootstrap fluid layout
        (12 columns: span 10, offset 1 centers the content and adds a margin on each side)
    -->
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span10 offset1">
                <h1 class="well">

                    <b>Store </b>
                </h1>
                <!-- <a href="#Index.html">Click here to navigate to Store</a>-->
                <div ng-view ></div>
            </div>
        </div>
    </div>
</body>
</html>

主页视图:

var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var ts = require('gulp-typescript');

//  Task that is used to compile the Typescript in JS 
gulp.task('typescriptCompilation', function () {
  return gulp.src('scripts/*.ts')
    .pipe(ts({
        noImplicitAny: true,
        out: 'output.js'
    }))
    .pipe(gulp.dest('scripts')); 
});

//  Task that is used to minify anf concatanate the JS into one file for distribution
gulp.task('minifyAndConcat', function() {
  return gulp.src('scripts/*.js') // read all of the files that are in script/lib with a .js extension
    .pipe(concat('all.min.js')) // run uglify (for minification) on 'all.min.js'
    .pipe(uglify({mangle: false})) // run uglify (for minification) on 'all.min.js'
    .pipe(gulp.dest('dist/js')); // write all.min.js to the dist/js file
});

2 个答案:

答案 0 :(得分:2)

请检查变量的大小写.id而不是.Id

{{product.id}} {{product.imageUrl}} {{product.name}} {{product.category}}

答案 1 :(得分:1)

锚点标记优先于href over ng-click,因此不会起作用。 我修改了我的代码如下:

@echo off
setlocal

rem The format of %TIME% is HH:MM:SS,CS for example 23:59:59,99
set STARTTIME=%TIME%
TIMEOUT 10
set ENDTIME=%TIME%

rem output as time
echo STARTTIME: %STARTTIME%
echo ENDTIME: %ENDTIME%

rem convert STARTTIME and ENDTIME to centiseconds
set /A STARTTIME=(1%STARTTIME:~0,2%-100)*360000 + (1%STARTTIME:~3,2%-100)*6000 + (1%STARTTIME:~6,2%-100)*100 + (1%STARTTIME:~9,2%-100)
set /A ENDTIME=(1%ENDTIME:~0,2%-100)*360000 + (1%ENDTIME:~3,2%-100)*6000 + (1%ENDTIME:~6,2%-100)*100 + (1%ENDTIME:~9,2%-100)

rem calculating the duratyion is easy
set /A DURATION=%ENDTIME%-%STARTTIME%

rem we might have measured the time in between days
if %ENDTIME% LSS %STARTTIME% set set /A DURATION=%STARTTIME%-%ENDTIME%

rem now break the centiseconds down to hors, minutes, seconds and the remaining centiseconds
set /A DURATIONH=%DURATION% / 360000
set /A DURATIONM=(%DURATION% - %DURATIONH%*360000) / 6000
set /A DURATIONS=(%DURATION% - %DURATIONH%*360000 - %DURATIONM%*6000) / 100
set /A DURATIONHS=(%DURATION% - %DURATIONH%*360000 - %DURATIONM%*6000 - %DURATIONS%*100)

rem some formatting
if %DURATIONH% LSS 10 set DURATIONH=0%DURATIONH%
if %DURATIONM% LSS 10 set DURATIONM=0%DURATIONM%
if %DURATIONS% LSS 10 set DURATIONS=0%DURATIONS%
if %DURATIONHS% LSS 10 set DURATIONHS=0%DURATIONHS%

rem outputing
echo STARTTIME: %STARTTIME% centiseconds
echo ENDTIME: %ENDTIME% centiseconds
echo DURATION: %DURATION% in centiseconds
echo %DURATIONH%:%DURATIONM%:%DURATIONS%,%DURATIONHS%

endlocal
goto :EOF